Hi,
Im designing an ‘L-System’ (Lindenmayer System) in flash which generates random shapes using lines working around rewrite rules. I’ve got so far and my program seems to be outputting the correct rewrite rules but I just can’t seem to get it to draw according. I’ll post my code below, if someone could help that’d be great. cheers ![]()
**draw_btn.onPress = function() {
trace (“Currentstring: " + currentstring);
applyRewriteRules();
trace(” --> " + currentstring);
displaystring();
drawstring();
}
// The Fibonacci Sequence
fibonacci_btn.onPress = function() {
seed = “F”;
f_rewrite = “G”
g_rewrite = “FG”
currentstring = seed;
};
// The Dragon Curve
dragon_btn.onPress = function() {
seed = “G”;
g_rewrite = “G+F”
f_rewrite = “G-F”
currentstring = seed;
};
// The Sierpinski Triangle:
sierpinski_btn.onPress = function() {
seed = “F”;
f_rewrite = “G-F-G”
g_rewrite = “F+G+F”
currentstring = seed;
};
// Koch curve
koch_btn.onPress = function() {
seed = “F”;
f_rewrite = “F+F-F-F+F”
currentstring = seed;
};
function applyRewriteRules(){
trace (“Apply rewrite rules”);
dummy_str = “”;
for(i = 0; i <currentstring.length; i++){
if (currentstring.charAt(i) == "F"){
dummy_str += f_rewrite;
}
else if (currentstring.charAt(i) == "G"){
dummy_str += g_rewrite;
}
else dummy_str += currentstring.charAt(i);
}
currentstring = dummy_str;
}
function drawstring(){
trace (“Draw String”);
_root.removeMovieClip(line_mc);
createEmptyMovieClip(“line_mc”, 10);
line_mc.lineStyle(1, 0x000000, 100);
line_mc.moveTo(0, 0);
currentX = 0;
currentY = 0;
xstep = 0;
ystep = 0;
startAngle = 0;
changeAngle = 90;
MAX_WIDTH = 300;
MAX_HEIGHT = 300;
for(i = 0; i <currentstring.length; i++){
}
if (currentstring.charAt(i) == “F”){
xStep = pathStepMath.cos(radiansTurned);
currentX += xStep;
yStep = pathStepMath.sin(radiansTurned);
currentY -= yStep;
line_mc.lineTo(currentX, currentY);
}
else if (currentstring.charAt(i) == “G”){
xStep = pathStepMath.cos(radiansTurned);
currentX += xStep;
yStep = pathStepMath.sin(radiansTurned);
currentY -= yStep;
line_mc.lineTo(currentX, currentY);
}
else if (testChar == ‘-’) {
startAngle = (startAngle - changeAngle)%360;
radiansTurned = (startAngle/180)*Math.PI;
}
else if (testChar == ‘+’) {
startAngle = (startAngle + changeAngle)%360;
radiansTurned = (startAngle/180)*Math.PI;
}
currentstring = dummy_str;
}**