Copyright © University of Cambridge. All rights reserved.

'Von Koch Curve' printed from https://nrich.maths.org/

Show menu


This is a Logo program to draw the Von Koch curve.

You can download a free copy of the MSW Logo software from http://www.softronix.com/logo.html

to allvonkoch
;draws 6 stages on same screen
cs pu fd 100 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 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

to vonkoch1
;superimpose 6 stages
cs pu bk 300 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