turtle = new CLSTurtle(startAngle, 0 - Xmin, 0 - Ymin,
xoff, yoff, xscale, yscale);
}
for (int pos = 0; pos < path.length(); pos++) {
switch (path.charAt(pos)) {
case '+':
turtle.rotate(rotAngle);
break;
case '-':
turtle.rotate(-rotAngle);
break;
case '[':
turtleStack.push(turtle);
turtle = new CLSTurtle(turtle);
break;
case ']':
turtle = (CLSTurtle) turtleStack.pop();
break;
case 'f':
turtle.jump();
break;
case 'F':
if (g == null) {
includePt(turtle.X, turtle.Y);
turtle.jump();
includePt(turtle.X, turtle.Y);
} else {
turtle.draw(g);
}
break;
default:
break;
}
}
}
void includePt(float x, float y) {
if (x < Xmin)
Xmin = x;
if (x > Xmax)
Xmax = x;
if (y < Ymin)
Ymin = y;
if (y > Ymax)
Ymax = y;
}
public String getAppletInfo() {
return "Title: CLSFractal 1.1f, 27 Mar 1995 \nAuthor: Jim Graham \nA (not yet) Context Sensitive L-System production rule. \nThis class encapsulates a production rule for a Context Sensitive\n L-System \n(pred, succ, lContext, rContext). The matches() method, however, does not \n(yet) verify the lContext and rContext parts of the rule.";
}
public String[][] getParameterInfo() {
String[][] info = {
{"level", "int", "Maximum number of recursions. Default is 1."},
{"incremental","boolean","Whether or not to repaint between recursions. Default is true."},
{"delay","integer","Sets delay between repaints. Default is 50."},
{"startAngle","float","Sets the starting angle. Default is 0."},
{"rotAngle","float","Sets the rotation angle. Default is 45."},
{"border","integer","Width of border. Default is 2."},
{"normalizeScale","boolean","Whether or not to normalize the scaling. Default is true."},
{"pred","String","Initializes the rules for Context Sensitive L-Systems."},
{"succ","String","Initializes the rules for Context Sensitive L-Systems."},
{"lContext","String","Initializes the rules for Context Sensitive L-Systems."},
{"rContext","String","Initializes the rules for Context Sensitive L-Systems."}
};
return info;
}
}
/**
* A Logo turtle class designed to support Context sensitive L-Systems.
*
* This turtle performs a few basic maneuvers needed to support the
* set of characters used in Context sensitive L-Systems "+-fF[]".
*
* @author Jim Graham
* @version 1.1f, 27 Mar 1995
*/
class CLSTurtle {
float angle;
float X;
float Y;
float scaleX;
float scaleY;
int xoff;
int yoff;
public CLSTurtle(float ang, float x, float y,
int xorg, int yorg, float sx, float sy) {
angle = ang;
scaleX = sx;
scaleY = sy;
X = x * sx;
Y = y * sy;
xoff = xorg;
yoff = yorg;
}
public CLSTurtle(CLSTurtle turtle) {
angle = turtle.angle;
X = turtle.X;
Y = turtle.Y;
scaleX = turtle.scaleX;
scaleY = turtle.scaleY;
xoff = turtle.xoff;
yoff = turtle.yoff;
}
public void rotate(float theta) {
angle += theta;
}
public void jump() {
X += (float) Math.cos(angle) * scaleX;
Y += (float) Math.sin(angle) * scaleY;
}
public void draw(Graphics g) {
float x = X + (float) Math.cos(angle) * scaleX;
float y = Y + (float) Math.sin(angle) * scaleY;
g.drawLine((int) X + xoff, (int) Y + yoff,
(int) x + xoff, (int) y + yoff);
X = x;
Y = y;
}
}
/**
* A (non-)Context sensitive L-System class.
*
* This class initializes the rules for Context sensitive L-Systems
* (pred, succ, lContext, rContext) from the given java.applet.Applet's attributes.
* The generate() method, however, does not (yet) apply the lContext