In the last tutorial, we wrote some Python programs to generate the Fibonacci sequence (0,1,1,2,3,5,8,13,21,34 etc.). It may have seemed that this was a rather dry exercise in coding with no relevance to reality. But in fact, the Fibonacci sequence and the Golden Ratio turn up unexpectedly in many places across the natural world. For example, sunflowers, which have opposing spirals of seeds, use the Fibonacci sequence to efficiently distribute their seeds in the most compact space (see here).
Recall that the ratio of neighbouring elements in the Fibonacci sequence approaches the famous Golden Ratio:
i.e., 34/21 = 1.6190..., 55/34 = 1.6176..., 89/55 = 1.6182..., etc.
If we split a circle up into two parts in the ratio 1:1.618..., then angle subtended by the smaller part is called the Golden Angle.
The smaller part (in red) of the circle is the fraction
The Golden Angle is f x 360 degrees.
A beautiful image like the pattern above may be generated with a simple algorithm, which draws a filled circles using a loop. Let's call the loop variable j. Then, on the jth step:
Attached to this page is the Python program
To use the program, you will need to have installed the
On Windows / Mac OS X, installing matplotlib is a bit more complicated. Please see this page for details.
You can download the program by clicking on it in the web browser (e.g. Midori on the Raspberry Pi). Save it. Open IDLE. From the menu, choose File -> Open and select chromoSpirals.py. The code should appear in a new window. To run the code press F5, or, from the menu, choose Run -> Run Program.
The program asks for three values: the number of disks, the number of colours, and the offset to the Golden Angle. To generate the plot above, I entered 2000, 13 and 0. Try experimenting with different values.
There are many lines of code in this program which may be unfamiliar to you. However, you may be able to deduce what some of them do. For example, can you find the lines which read the user's input? (Look out for the
Try a range of choices for the number of disks, colours and offset. Have fun! Please send your most beautiful pictures to email@example.com