Technology: Logo
Topic: Fractals

For any one of the following problems,  create a menu screen which allows the user to choose between your basic embedded recursion design and the graphic which uses your embedded recursion design:

  1. Create a fractal  that  is based on any regular-sided polygon   you wish.
  2. For a closed fractal pattern, use the fractal  you generated   in #1 and place two of them to form a square. This is called the quadric  Koch island.
  3.  Create an open fractal pattern, called a snowflake, using a  REPEAT and an angle turn with one of your fractals
  4. Try putting together   different fractals to create "monster"  shapes.
  5. Use embedded recursion to building a 'tree' with the following procedure as the basis:
    TO TREE  : LENGTH
    FD: LENGTHRT 45 FD  :LENGTH/2  BK  :LENGTH/2 LT 90 
    FD: LENGTH/2 BK: LENGTH/2 
    RT 45 BK  : LENGTH
    END
  6. Change the angles in your tree to generate a more "nature-like" tree.
  7. The basic fractal  has three changes in every line, while the C-Curve has only two. Use  the following procedure (which generates a C-Curve to create your own C-Curve graphic.
    TO C.CURVE  : LEN  : ORDER
    IF  :ORDER = 0 [FD :LEN STOP]
    LT 45
    C.CURVE (:LEN / SQRT 2) :ORDER- 1
    RT 90
    C.CURVE (: LEN / SQRT 2) :ORDER- 1
    LT 45
    END


  8. The dragon curve uses the C-Curve as its base design, only using a 90 degree twist, alternating left and right in every other order. Using the following procedures, create a dragon graphic you like.

    TO BEGIN.DRAGON
    CG PU SETPOS [-50 0] HT PD
    DRAGON 50 7 1
    END

    TO DRAGON :LEN :ORDER :SIGN
    IF :ORDER = 0 [FD :LEN STOP]
    DRAGON ( :LEN / SQRT 2)  ( :ORDER - 1 )  1
    LEFT 90 *  : SIGN
    DRAGON ( :LEN / SQRT 2)  ( :ORDER - 1 )  -1
    END

    NOTE: The switching back and forth from right to left  is done through the use of the :SIGN variable
                           .

  9. Create a fractal  and then print out the various lengths of the fractal  as you change  the' LIMIT to demonstrate the  idea of using fractals for measurement

Commands:  IFELSE, STARTUP, SQRT

 Sample Menu Procedure

to menu
pr [What  is your name?]
make "myname rl
pr (se [Hi]  :myname [Please choose from the menu what you would like to see.] )
pu setpos [wherever ] pd label  ????....  (menu goes here)
repeat 8[pr "] make "'choice rl
ifelse :choice = [a] [gp "graphicl]  [ gp "graphic2]
end

or instead of using the label  command, use INSERT CHAR 32 (the blank space).So lines 6 and 8 above would become:

repeat 3 [pr "]
repeat 5[insert chart 32] pr [to see the dragon - type A]  ....

Fractals Based on Triangles  

to move
cg pu setpos [ -100 0] pd rt 90
end

to tf0 :length
fd: length
end

to tf1 :length
tf0 :length/3
lt 60 tf0 :length/3
rt 120 tf0 :length/3
lt 60 tf0 :length/3
end

to tf2: length
tfl  :length/3
lt 60 tfl  :length/3
rt 120 tfl  :length/3
lt 60 tf1  :length/3
end

to trifrac :order :length
if :order = 0[  fd :length stop]
trifrac :order-1  :length/3
lt 60 trifrac :order-1  :length/3
rt 120 trifrac :order-1  :length/3
lt 60 trifrac :order-1  :length/3
end

Embedded Recursion

Embedded recursion takes place when the recursive call is within a procedure is opposed to tail-end recursion which takes place at the end of a procedure. With embedded recursion, commands within a procedure are stacked and then executed when the recursion  is stopped. Wonderful graphics are created with embedded recursion: fractals, trees, dragon curves, space-filling curves, and so forth.

Example

Procedure   Action
1. TO COUNT.DOWN.AND.UP :N     say N=3
2. IF  :N=O [STOP]   FALSE  
3. PR  :N     goto line 7  
4. COUNT.DOWN.AND.UP :N-1     output line 6 which is 3  
5. PR  :N  
6. END
7. TO COUNT.DOWN.AND.UP.  :N N=2  
8. IF  :N  =  0  [STOP]   FALSE  
9. PR :N  goto line13  
10.   COUNT.DOWN.AND.UP :N-1    output line 5 which is 2  
11. PR :N  
12. END  
13. TO COUNT.DOWN.AND.UP :N   N=1
14. IF  :N=  0  [STOP] FALSE  
15. PR  :N   goto line 19  
16. COUNT.DOWN.AND.UP    :N-1    output line 4 which is 1  
17. PR :N
18. END  
19. TO COUNT. DOWN .AND. UP :N    N=0 
20. IF  :N=O  [STOP]     TRUE --STOP goto line 17  
21. PR :N  
22. COUNT. DOWN .AND. UP :N  
23. PR :N
24. END  

 


 2000-01  M. Llarull - Department of Mathematics - NJTQEC - William Paterson University