Difference between revisions of "Recursion"

From CodeStuff
Jump to: navigation, search
 
Line 1: Line 1:
<edcode>
+
<edcode>function drawThing(x,y,size) {
 
+
function drawThing(x,y,size) {
+
 
   if (size < 1) return;  //do nothing if the size is tiny
 
   if (size < 1) return;  //do nothing if the size is tiny
  
Line 21: Line 19:
 
What would happen if we replaced the three horizontal lines in drawThing with a horizontal line with a kink by using drawThing to draw itself.
 
What would happen if we replaced the three horizontal lines in drawThing with a horizontal line with a kink by using drawThing to draw itself.
  
Instead of <code>drawLine(x,y,x+size,y)</code> do <code>drawThing(x,y,size/3);</code>
+
instead of drawLine(x,y,x+size,y)  do drawThing(x,y,size/3);
 
+
Instead of <code>drawLine(x+size,y-size,x+size*2,y-size)</code>  do <code>drawThing(x+size,y-size,size/3);</code>
+
 
+
Instead of <code>drawLine(x+size*2,y,x+size*3,y)</code>  do <code>drawThing(x+size*2,y,size/3);</code>
+

Latest revision as of 09:08, 13 August 2015


This program draws a thing by drawing five lines. Across-Up-Across-Down-Across. It's like a horizontal line with a kink in the middle.

What would happen if we replaced the three horizontal lines in drawThing with a horizontal line with a kink by using drawThing to draw itself.

instead of drawLine(x,y,x+size,y) do drawThing(x,y,size/3);