Tutorials‎ > ‎

Week 2(a): Golden Angle, Sunflowers and Chromospirals

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).

Sunflower head
Above: A picture of a sunflower, taken from a fascinating blog post on the Golden Ratio in nature. Right: a Fibonacci disk generated by a Python program on the Raspberry Pi (see below).

The Golden Angle

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. 

Chromospirals

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:
  • Draw a circle of diameter phi, at a distance sqrt(j) from the centre of the disk, and at an angle j x a degrees.
Here "a" is an angle, which we may choose. Rather wonderfully, if we choose a = f x 360 degrees, i.e. the Golden Angle, then the arrangement of circles turns out be very closely-packed: the circles are close together but do not overlap. This turns out to be an excellent arrangement for (e.g.) seeds in a sunflower head.

A program


Attached to this page is the Python program chromoSpirals.py which was used to generate plots such as the image above. The program was written by Peter Derlien, a researcher in the School of Mathematics and Statistics at University of Sheffield. He calls these patterns "Chromospirals".

Install Matplotlib


To use the program, you will need to have installed the numpy and matplotlib package. On a Raspberry Pi, the numpy package is installed by default on Raspbian. To install matplotlib, you need your RPi to have a network connection. Open a terminal (e.g. LXTerminal), and at the prompt, type:

sudo apt-get install python-matplotlib

On Windows / Mac OS X, installing matplotlib is a bit more complicated. Please see this page for details.

Getting and running the program

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 input function). Can you find the loop which draws the circles? And what is the meaning of the 'offset' variable?

Try a range of choices for the number of disks, colours and offset. Have fun! Please send your most beautiful pictures to pi3challenge@sheffield.ac.uk

Challenges

  1. Can you deduce which parameters were used to generate the plots below?
 (a)
 (b)
ċ
Sam Dolan,
24 Mar 2013, 14:24
Comments