# Why won't this draw? (Need help asap)

**URL:** <https://forum.kirupa.com/t/why-wont-this-draw-need-help-asap/281061>\
**Category:** flash\
**Created:** [February 4, 2009, 2:39pm UTC](https://forum.kirupa.com/t/why-wont-this-draw-need-help-asap/281061 "2009-02-04T14:39:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![smcshane123](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@smcshane123](https://forum.kirupa.com/u/smcshane123)\
**Post date:** [February 4, 2009, 2:39pm UTC](https://forum.kirupa.com/t/why-wont-this-draw-need-help-asap/281061/1 "2009-02-04T14:39:16Z")

</div>

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 ![](http://forum.kirupa.com/uploads/kirupa/798/c985a958819d8917.gif)

\*\*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 &lt;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 = pathStep_Math.cos(radiansTurned);  
currentX += xStep;  
yStep = pathStep_Math.sin(radiansTurned);  
currentY -= yStep;  
line\_mc.lineTo(currentX, currentY);

}

else if (currentstring.charAt(i) == “G”){  
xStep = pathStep_Math.cos(radiansTurned);  
currentX += xStep;  
yStep = pathStep_Math.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;

```

}\*\*
