| Seirpinski Gaskets and
Trees with LOGO programming [Updated in July 1998 from an article in Fractal Report magazine No.8, March 1990. All graphics have been created using WinLogo using procedures available in Mathematics Through WinLogo] |
||||||
|
Introduction | |||||
|
For young schoolchildren to fully appreciate the wonder of fractals, they need to be convinced that the computer is not doing something mysterious and magical, forever beyond their ken. This is often a difficult problem to overcome considering the esoteric programs (including BASIC) often used. LOGO offers a solution. LOGO is the programming language that most pupils meet, usually at middle or secondary school. It is designed to be easy to master and is interactive. The following LOGO procedures are written in RM LOGO for use with Research Machines Nimbus computers, but are easily adaptable to any other system. They make use of two procedures, "face" and "distanceto" which are available in the pack "LOGO Microworlds" published by ATM. |
||||||
| Logo procedures | ||||||
|
To produce the triangular Sierpinski gasket, first define the procedures opposite: The point about these procedures is that they are relatively easy to read and understand. set.up.triangle simply positions three turtles as far apart as possible on the screen and then tells a fourth turtle (which will appear by default at the centre of the screen) to "lift" so that it does not draw a line when it moves. The position of turtle 4 can be altered arbitrarily if required by entering, for example, setpos [-20 50] step chooses as "random.vertex" one of the three corner turtles, get turtle 4 to face it, then makes turtle 4 move halfway towards it. Finally, a mark is made by making the turtle move a minimal distance forward and back. this method of making a mark is instructive in that it brings out the limitations of the technology and the display screen in particular, in that results are always limited by the screen pixels. go repeats step forever (until you press ESCAPE!) |
set.up.triangle noturtles tell 1 setpos [-153 -89] tell 2 setpos [153 -89] tell 3 setpos [0 92] tell 4 lift step make 'random.vertex pick 3 face :random.vertex fd 0.5*(distanceto :random.vertex) drop fd 0.1 bk 0.1 lift go forever [step]
|
|||||
| To begin the process | ||||||
| To begin with, one step at a time can be shown, then the procedure allowed to take off by entering go; otherwise you can simple enter set.up.triangle go. The process is slow, but what is happening is obvious and does not allow the picture to appear seemingly by magic. Indeed, the gradual building up of the fractal image allows children to form hypotheses about it. What happens if the turtle moves not halfway towards a random vertex but some other ration | ||||||
|
Here's the effect of ratios of 0.1 and 0.45: |
![]() ![]() |
|||||
|
Here's an animation of the process for values between of 0.1 and 0.9: |
![]() |
|||||
|
Children may then be able to experiment with procedures for creating these fractal images based on other polygons. For example the illustration opposite is based on 4 vertices and at each step the turtle moves 2/3 of the way to the chosen random.vertex. |
![]() |
|||||
| Other examples of fractal-like structures | ||||||
|
LOGO is also an excellent way of exploring fractal trees, through its ability to cope with recursive procedures, for example: tree 60, for example, calls itself twice, but avoids falling into an infinite loop through the if statement ("stop" returns control to the previous level). It creates a simple symmetric tree - and can be improved on a lot! |
tree 'distance if :distance < 5 [stop] forward :distance right 30 tree :distance-10 left 60 tree :distance-10 right 30 back :distance |
![]() |
||||
| However, we must not pretend that recursion is an easy concept to grasp - but LOGO does provide a reasonable environment for attempting it. | ||||||
| A Julia set | "Brownian motion" | |||||
|
Any other ideas for "simple" examples of fractal programming? Here's a Julia set:
|
Here's an example
of random movement of particles from a fixed starting point, known as Brownian
motion:
|
|||||