Take a look at this chamomile flower:

Pretty, isn't it? Well, what if I told you that this wasn't actually one flower?

A lot of flowers (including sunflowers, chamomiles, daisies and others) actually consist of many very small flowers (the black dots on sunflowers) on a flower head. These miniature flowers are called florets, and they are arranged in a very special way.

Basically, the nth floret's position on a flower head is (in polar coordinates):

where c = 1 (Note that 137.508 degrees = golden angle. You don't have to use this exact precision.)

This causes the florets to be formed in a spiral called Fermat's Spiral. The positioning of the florets also is connected with Fibonnaci numbers, but that's a tale for another time.

So, here's the challenge. Given an integer n as input, calculate the positions of the first n florets and plot them. This is , so I do actually want you to display the points in either a window of some sort or outputted as data in some common image format to STDOUT or a file. Other than that, this challenge should be fairly straightforward. It's , so shortest code wins. GLHF!

Here is a sample picture of what an output might look like:

  • \$\begingroup\$ Are we allowed to draw the spiral upside down? \$\endgroup\$
    – lirtosiast
    Oct 8, 2015 at 12:58
  • 1
    \$\begingroup\$ FWIW many fruits display this pattern, such as the pineapple, agauje, and pinecone. This should not be surprising since fruits develop from flowers. Interestingly some cactus bodies also display this pattern. My favorite is the fractal Romanesco broccoli: en.wikipedia.org/wiki/Romanesco_broccoli#/media/… \$\endgroup\$
    – user151841
    Oct 9, 2015 at 16:10
  • 1
    \$\begingroup\$ That's cool! I've seen Romanesco broccoli before; I think it's really cool how they have that fractal pattern. Maybe I could make a challenge about that... \$\endgroup\$ Oct 9, 2015 at 21:04

14 Answers 14


TI-BASIC, 34 bytes

For the TI-83+/84+ series of calculators.

Input N
Polar                      ;Displays polar mode graphs to graph screen
Dot                        ;Prevents lines from connecting points
DispGraph                  ;Displays graph screen

This considers the dot at the origin to be the 0th dot.

Thanks to the one-byte sinh⁻¹( token, 2πe^(-2sinh⁻¹(.5 is a short way of getting the golden angle in radians. This is derived from the fact that e^(sinh⁻¹(.5 is the golden ratio.

Here are screenshots for N=50.

(Yes, that's a 96x64 monochrome display on a TI-84+. The newer color calculators have a resolution upgrade, but still have only 3.7% the pixels of an iPhone.)

Without coordinates displayed

Press TRACE to step through each point.

With coordinates

  • 5
    \$\begingroup\$ TI-BASIC is a natural choice for polar coordinates. \$\endgroup\$ Oct 8, 2015 at 3:30
  • \$\begingroup\$ How did you determine the number of bytes? Looks like a lot more than 34. A pre-programmed key, as sinh⁻¹ appears to be (if I understood your explanation), would count as more than one byte. \$\endgroup\$
    – DavidC
    Oct 10, 2015 at 7:36
  • \$\begingroup\$ @DavidCarraher TI-BASIC is tokenized; all of these tokens are one byte each in the calculator's memory. \$\endgroup\$
    – lirtosiast
    Oct 10, 2015 at 14:26
  • 1
    \$\begingroup\$ You can determine the number of bytes in a program by going to Mem (2nd->+)->7. You will then see a list of all programs on your calculator and the number of bytes they take up. Note that all TI-BASIC programs have a 9 byte header + the number of bytes in the name, so be sure to subtract those to get the proper byte count. \$\endgroup\$ Oct 10, 2015 at 14:57
  • \$\begingroup\$ Syntax error on -2sinh^-1 \$\endgroup\$ Feb 8, 2016 at 15:12

Python 2, 85 82 81 bytes

from pylab import*
for i in arange(0,input(),2.39996):polar(i,sqrt(i),'o')

Shortened by one byte by marinus.

Using the golden angle in radians. Byte length is the same if I used 137.508 instead, but somehow doesn't look as good. Generates a polar plot using pylab. Below is when 300 (for the older version) is the input and 7000 (for the newer version) is the input. Could round the angle up to 2.4 to lower the number of bytes to 77.

Older version when input is 300

Newer version when input is 7000

Here's a longer version that produces a cleaner look by removing the grid and axis:

from pylab import *
def florets(n):
    for i in arange(0, n, 2.39996):polar(i, sqrt(i), 'o')
    grid(0)#turn off grid
    xticks([])#turn off angle axis
    yticks([])#turn off radius axis

The reason for the different colors is because each point is plotted separately and treated as its own set of data. If the angles and radii were passed as lists, then they would be treated as one set and be of one color.

  • 1
    \$\begingroup\$ I think this is the prettiest answer by far. It's very cool to see the clear spiral patterns in the center. \$\endgroup\$ Oct 8, 2015 at 23:10
  • \$\begingroup\$ You could save a byte by using a normal for loop instead of a list comprehension. It'd have to be on its own line, but ; and \n are the same length, so that doesn't matter. I.e.: from pylab import* - for i in arange(0,input(),2.39996):polar(i,sqrt(i),'o') - show() \$\endgroup\$
    – marinus
    Oct 9, 2015 at 7:50
  • \$\begingroup\$ @marinus but then its no longer a supercool one liner! But thanks, I've added it in. \$\endgroup\$
    – Status
    Oct 9, 2015 at 16:20

Blitz 2D/3D, 102 bytes

(The very FIRST EVER Blitz 2D/3D answer on this site!)

Graphics 180,180
Origin 90,90
For i=1To n
Plot r*Cos(t),r*Sin(t)

An input of 50 fills the window. (Yes, I could shave off two bytes by doing Graphics 99,99, but that's not nearly so visually interesting or useful.)

50 florets

Prettier version (and exits more nicely):

Graphics 400,400
Origin 200,200

n=Input("How many florets? ")

For i = 1 To n
    t# = i * 137.508
    r# = Sqr(t)

    Oval r*Cos(t)-3,r*Sin(t)-3,7,7,1


200 florets example

  • \$\begingroup\$ hey, neat! i didn't know about blitz before reading this. \$\endgroup\$ Oct 8, 2015 at 7:32
  • \$\begingroup\$ Wow, Blitz3D was my first language some 15 years ago :D... sigh.. :'( \$\endgroup\$
    – noncom
    Oct 8, 2015 at 10:45
  • \$\begingroup\$ Degrees as the default? "Interesting"... \$\endgroup\$
    – lirtosiast
    Oct 8, 2015 at 11:00
  • 1
    \$\begingroup\$ @noncom: It was the first language that I really made significant programs in. Eight years ago. It's still one of my top two best languages today (the other being Python). \$\endgroup\$ Oct 8, 2015 at 18:20
  • 1
    \$\begingroup\$ @noncom, It was my first language too. I wonder how I'd feel using it professionally now. \$\endgroup\$ Oct 9, 2015 at 15:32

Mathematica, 43 42 bytes


This is an unnamed function taking an integer argument, e.g.

enter image description here
The screenshot uses an older version, but the output looks the same.

Mathematica actually has a built-in GoldenAngle for even more accurate results, but that's longer than 2.39996.

  • \$\begingroup\$ GoldenAngle! Is it a new function in Mathematica 10.2? \$\endgroup\$
    – alephalpha
    Oct 9, 2015 at 6:58
  • \$\begingroup\$ @alephalpha Yep. \$\endgroup\$ Oct 9, 2015 at 7:14

MATLAB, 42 bytes


Gets the input number, creates a range from 1 to that number.

Multiplies the range by the golden angle in radians (the value used is closer to the true value than 137.508 degrees to 6 s.f.).

Then simply plots theta vs. r on a polar coordinates chart using dots. Here shown with 2000 points


A slightly prettier looking graph (no grid lines) would be this code:

t=2.39996*(1:input(''));[x,y]=pol2cart(t,t.^.5);plot(x,y,'.');axis equal

Though that is at the expense of 31 bytes. Again here is it shown with 2000 points


  • \$\begingroup\$ I like the polar solution, I've never used that one before. I think you can save two bytes by using t.^.5 instad of sqrt(t)! \$\endgroup\$
    – flawr
    Oct 10, 2015 at 13:21
  • \$\begingroup\$ @flawr Thanks. Two bytes indeed saved. \$\endgroup\$ Oct 10, 2015 at 14:42

R, 58 55 54 bytes


This requires the plotrix package to be installed, but the package doesn't have to be imported because we're referencing the namespace explicitly.


# Read a number of STDIN
n <- scan()

x <- 2.39996*(1:n)

# The rp.type = "s" option specifies that we want to plot points rather
# than lines (the default)
plotrix::radial.plot(lengths = sqrt(x), radial.pos = x, rp.type = "s")

Example output for n = 1500:

enter image description here

Saved 3 bytes thanks to plannapus!


R, 55 54 bytes


Here is the result for n=1000:

enter image description here

Edit: Saved 1 byte using partial matching of arguments (as instead of asp) thanks to @AlexA.!


R, 48 47 bytes

I think this is sufficiently different from the other R solutions so far. This one uses complex vectors to construct the coordinates. the sqrt of t and t are put into the modulus and argument parameters and the x, y are taking from the real and imaginary. Thanks to @AlexA. for the byte.


enter image description here

  • 1
    \$\begingroup\$ Not only is it different, it's shorter! +1. \$\endgroup\$ Oct 8, 2015 at 23:10
  • \$\begingroup\$ You can save a byte using partial matching of function parameters: as can be used in place of asp. \$\endgroup\$
    – Alex A.
    Oct 8, 2015 at 23:14
  • \$\begingroup\$ @AlexA. Thanks Alex, I keep forgetting to test those ones :) \$\endgroup\$
    – MickyT
    Oct 9, 2015 at 0:13

Html+JavaScript 179

<canvas id=C></canvas><script>n=1500,C.width=C.height=400,T=C.getContext('2d');for(n=prompt(M=Math);n--;)r=M.sqrt(t=n*2.4)*9,T.fillRect(M.cos(t)*r+200,M.sin(t)*r+200,2,2)</script>


Jolf, 25 bytes


enter image description here

(output for n = 5000)

Try it online. (note that the resulting spiral is small)

Non-competing since Jolf was created after this challenge. This is 25 bytes when encoded with ISO-8859-7, and it contains one unprintable (here's a hexdump):

0000000: 7947 4096 404b 796f cc7a 5844 794f 5548  yG@.@Kyo.zXDyOUH
0000010: 2a48 6db0 7954 272e 7d                   *Hm.yT'.}


yG@@K                      goto (150,75) (center of the canvas)
     yo                    set current location as the origin
       MzX                 map over range 1...input
          D                start of function
           yO              goto polar coordinates ....
             UH            radius: square root of argument
               *Hm°        angle: argument times golden angle
                   yT'.    draw a dot there
  • 2
    \$\begingroup\$ Well. I think I'll have to look into Jolf now, despite the strange encoding. \$\endgroup\$
    – lirtosiast
    Feb 6, 2016 at 0:27

K (oK) + iKe, 37 bytes


Try it online!

a function which takes n on the right. Uses the approximate 2.4 radian measure.

-8 bytes from JohnE.


 draw::                                       globally set draw to:
       {                                }     the following function
                                         '!x  run on range 0..input-1
        (                              )      create an array:
                             t:x*2.4          multiply right arg by 2.4, set to t
                 (cos;sin)@\:                 apply cos and sin on each
            (%t)*                             multiply by sqrt(t)
         80+                                  add 80 (for compatibility with any size, change to ((w;h)%2)+)

Python 2, 74 bytes

from pylab import*

Tcl/Tk, 114

grid [canvas .c]
proc P n {time {incr i
.c cr o [lmap h {cos sin cos sin} {expr sqrt($i*2.4)*$h\($i*2.4)+99}]} $n}

Example of usage:

P 1024

and outputs the window

enter image description here


MATL, 20 bytes


Try it at MATL Online!

The golden angle, 137.708deg = pi*(3-sqrt(5))rad = 2.39996...rad is approximated as 2.4rad.

The following version (25 bytes) uses the exact value, up to double floating-point precision:


Try it at MATL Online!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.