Logo programme to draw fractal trees

This programme was written by Lewis Pike, and is distributed freely from the MatheMagic website. If you would like to use this programme, please include an attribution to the programmer and a link to the MatheMagic home page (http://www.mathemagic.org)

To be able to use this programme you need to download a copy of logo for your machine and install it. Then you can copy the programme below into its command editor, and run it to draw fractal trees. To draw a tree, enter TREE n l into your command line, where n is the number of branches at each point (2 to 4) and l is the length of the trunk (4 to 256). If you haven't got logo already, you can download it from the ATM website, which hosts a useful logo resouce page.

If you found this from the Maths of Big Molecules 'Fun with Fractals' page, you might notice that this programme is more or less fractal too. Each 'Tree' routine is similar to the others, but it gets a bit bigger each time you have more branches!

If you would like to see the Maths of Big Molecules material, you can go to the index or straight to the Fun with Fractals section.

to tree :number :length
cs
if :length>256 [print [Please choose a length between 4 and 256]]
if :length>256 [stop]
if :length<4 [print [Please choose a length between 4 and 256]]
if :length<4 [stop]
if :number<2 [print [Please choose a number between 2 and 4]]
if :number<2 [stop]
if :number>4 [print [Please choose a number between 2 and 4]]
if :number>4 [stop]
setpensize [3 3]
setpencolor [0 223 56]
if :number=2 [tree2 :length] [if :number=3 [tree3 :length] [tree4 :length]]
end
 
to tree2 :length
if :length <2 [stop]
lt 45
forward :length
tree2 :length/2
back :length
rt 90
forward :length
tree2 :length/2
back :length
left 45
end
 
to tree3 :length
if :length<2 [stop]
lt 45
forward :length
tree3 :length/2
back :length
rt 45
forward :length
tree3 :length/2
back :length
rt 45
forward :length
tree3 :length/2
back :length
lt 45
End
 
to tree4 :length
if :length<2 [stop]
lt 45
forward :length
tree4 :length/2
back :length
rt 30
forward :length
tree4 :length/2
back :length
rt 30
forward :length
tree4 :length/2
back :length
rt 30
forward :length
tree4 :length/2
back :length
lt 45
End