Julie Clune, as part of a Logo 15-word challenge, draws this rather nice simple flower:
Here’s the code:
repeat 11 [for [i 0 359] [fd 1 rt (sin :i / 2)]]
In Curly Logo, which has slightly anaemic syntax at the moment, the code is:
repeat 11 [ repeat 360 [ fd 1 rt sin (- repcount 1) / 2 ] ]
In the long term I see no reason why the original code shouldn’t work exactly as is with Curly Logo.
Someone has penned a rather cheeky comment under Clune’s code:
Why does the line match up exactly after drawing 11 petals?
What an excellent question.
The flower consists of repeating the same something 11 times. Let’s use the terminology of the question and call the repeated thing a petal:
repeat 360 [ fd 1 rt sin (- repcount 1) / 2 ]
So to work out why the line matches up after exactly 11 petals we need to work out how much turn the turtle makes for each petal.
Well it’s
sin 0 +
sin .5 +
sin 1 +
sin 1.5 +
…
sin 179.5
degrees.
This is an approximation to where sin is the sine function in degrees; with sin in radians it’s which is 2 × 360 ÷ π degrees (the definite integral evaluating to 2).
So each petal makes the turtle turn 2 × 360 ÷ π degrees or 2 ÷ π complete revolutions. Clearly this is irrational. So however many petals we draw we should never come back to exactly where we started.
But π is approximately 22/7, so each petal is approximately 2 × 360 ÷ (22 ÷ 7) degrees or 7 × 360 ÷ 11 degrees. So after 11 petals the turtle will have turned through 7 complete revolutions, approximately. The fact that Clune’s flower looks like it meets up is testimony to how well π is approximated by 22/7.
Leave a comment