Using MSW Logo
Download MSW Logo
Basic introduction to using Logo programs
More advanced
help
Programming
resources
Fractal programs in Logo
Fractal snowflake
von Koch (snowflake) curve
Sierpinski gasket
Cesaro fractal
Broccoli fractal
Forest of trees
Fractal
star
to star :a
lt 30
repeat 6[fd :a lt 60 fd :a rt 120]
rt 30
end
to star1 :a
lt 30
repeat 6[star (:a/3) pu fd :a pd lt 60 star (:a/3) pu fd :a pd rt 120]
rt 30
end
to star2 :a
lt 30
repeat 6[star1 (:a/3) pu fd :a pd lt 60 star1 (:a/3) pu fd :a pd rt 120]
rt 30
end
to star3 :a
lt 30
repeat 6[star2 (:a/3) pu fd :a pd lt 60 star2 (:a/3) pu fd :a pd rt 120]
rt 30
end
Go to top
Fractal
snowflake
to starout :a
star :a rt 180
repeat 6 [star :a/3 pu rt 150 fd :a lt 60 fd :a lt 30 pd]
end
to starout2 :a
star :a rt 180
repeat 6 [star :a/3 starout :a/3 pu lt 30 fd :a lt 60 fd :a lt 30 pd]
end
to starout3 :a
star :a rt 180
repeat 6 [star :a/3 starout :a/3
repeat 6[starout2 :a/9 pu rt 30 fd :a/3 rt 60 fd :a/3 rt 30] pu lt 30 fd :a
lt 60 fd :a lt 30 pd]
end
Go to top
von Koch (snowflake) curve
to allvonkoch
; draws 6 stages on same screen
cs pu fd 280 lt 90 fd 300 rt 90 pd
vonkoch2 200 0
pu rt 90 fd 250 lt 90 pd
vonkoch2 200 1
pu rt 90 fd 250 lt 90 pd
vonkoch2 200 2
pu bk 300 lt 90 fd 500 rt 90 pd
vonkoch2 200 3
pu rt 90 fd 250 lt 90 pd
vonkoch2 200 4
pu rt 90 fd 250 lt 90 pd
vonkoch2 200 5
ht
end
to vonkoch1
; superimposes 6 stages
cs pu lt 90 fd 200 rt 90 pd
vonkoch2 500 0
vonkoch2 500 1
vonkoch2 500 2
vonkoch2 500 3
vonkoch2 500 4
vonkoch2 500 5
end
to vonkoch2 :x :y
; draws single curve size :x stage :y at current cursor position
repeat 3 [side :x :y rt 120]
end
to vonkoch3
; draws sixth stage
cs pu bk 300 lt 90 fd 200 rt 90 pd
vonkoch2 500 5
end
to side :x :y
if :y = 0 [fd :x stop]
side :x/3 :y-1
lt 60
side :x/3 :y-1
rt 120
side :x/3 :y-1
lt 60
side :x/3 :y-1
end
Go to top
Sierpinski gasket
to allgasket
; note - draws 7 stages one after the other
cs gasket 1024 1024
gasket1 1024 512
gasket1 1024 256
gasket1 1024 128
gasket1 1024 64
gasket1 1024 32
gasket1 1024 16
ht
end
to gasket :x :n
;note - clears screen, positions cursor, draws gasket size x, smallest triangle
size y
cs pu bk 30 lt 90 fd 200 rt 90 pd
gasket1 :x :n
end
to gasket1 :x :n
; note - draws gasket size x, smallest triangle size y, from current position
if :x < :n [stop]
repeat 3 [gasket1 :x/2 :n fd :x/2 rt 120]
end
Go to top
Cesaro fractal
to allcesaro
; notes - draws 4 stages on same screen
cs pu fd 200 rt 90 fd 200 lt 90 pd
cesaro1 150 1
pu lt 90 fd 300 rt 90 pd
cesaro1 150 2
pu bk 200 pd
cesaro1 150 3
pu rt 90 fd 300 lt 90 pd
cesaro1 150 4
ht
end
to cesaro1 :s :n
; notes - draws cesaro size :s stage :n from cursor position
; start cesaro1 350 3 - positions cursor and draws stage3
repeat 4 [spike :s :n lt 90]
end
to singlecesaro :s :n
; notes - positions cursor, draws cesaro size :s stage :n
cs pu bk 250 rt 90 fd 150 lt 90 pd
cesaro1 :s :n
end
to spike :s :n
if :n = 0 [fd :s stop]
spike :s*0.453 :n - 1 lt 84
spike :s*0.453 :n - 1 rt 168
spike :s*0.453 :n - 1 lt 84
spike :s*0.453 :n - 1
end
Go to top
Broccoli fractal
to broccoli :x :y
; largest square has side x and smallest square has side y
; for example type broccoli 120 2
cs pu lt 90 fd 50 rt 90 pd
broccoli1 :x :y
ht
end
to broccoli1 :x :y
if :x < :y [stop]
square :x
fd :x lt 45
broccoli1 :x/sqrt(2) :y
pu rt 90 fd :x/sqrt(2) pd
broccoli1 :x/sqrt(2) :y
pu bk :x/sqrt(2) lt 45 pd bk :x
end
to square :x
repeat 4 [fd :x rt 90]
end
Go to top
Forest of trees fractal
to forest
cs pu fd 500 pd
sycamore1 150
tree 350 -310 120 20 6
tree 200 -290 80 25 6
tree -320 -280 110 27 7
ht
end
to tree :x :y :u :a :s
; draws tree1 at position (x,y)
pu setpos (list :x :y) pd
tree1 :u :a :s
end
to tree1 :u :a :s
; note - draws tree in current cursor position with size :u, angle :a, stage
:s
if :s = 0 [stop]
fd :u rt :a
tree1 :u*(0.5+0.04*random 10) :a :s - 1
lt 2*:a
tree1 :u*(0.5+0.04*random 10) :a :s - 1
rt :a bk :u
end
to sycamore1 :x
cs pu bk 300 pd
sycamore2 :x
end
to sycamore2 :x
if :x < 12 [stop]
fd :x
rt 25 sycamore2 :x*0.7
lt 25 sycamore2 :x*0.6
lt 28 sycamore2 :x*0.7
rt 28 bk :x
end
|