# Phyllotaxis Pattern in Python

In this tutorial, we’ll learn about the concept and implementation of the phyllotaxis pattern in Python.

Phyllotaxis is a common repeating spiral pattern in plants. The nomenclature was given in biology by Charles Bonnet. It looks something like this:

Mathematically, it is a Fibonacci sequence.  Auguste Bravais and Louis connected these pattern ratios to the Fibonacci sequence.

## What is a phyllotaxis pattern?

Phyllotaxis pattern is basically, an arrangement of seeds, leaves in the plant system. Spiral is a much relatable word for phyllotaxis. A Fibonacci sequence: a sequence of numbers where the third number is the sum of first two numbers, the fourth number is a sum of the second and third numbers, and so on.

fibonacci sequence: 0,1,1,2,3,5,8…. (0+1=1, 1+1=2, 1+2=3, 2+3=5, 3+5=8,….)

Whereas a Fibonacci spiral is more like a close packing of spheres, generating a dodecahedral tessellation showing pentaprismic faces.

#### Code:

Basic knowledge about turtle library in Python is helpful, refer- Basics of Turtle programming in Python.

We need to import math and turtle libraries, and then move to the functions segment.

The graphics portion is again divided into inner spiral math and outer spiral math.

#### Inception and inner spiral:

```import math
import turtle as TUR

#Making the inner spirals or
def Phy_patt( Tx, Start_draw_petaL, anglE = 138.508, size = 2, cS = 4 ):
TUR.pen(outline=1,pencolor="black",fillcolor="pink")
#filling the inside of our phyllotaxis
pI = anglE * ( math.pi / 180.0 )
X_center = 0.0
Y_center = 0.0

# loop until < cS
for nO in range (0, Tx ):
value_of_theta = nO * pI

x =rad * math.cos(value_of_theta) + X_center
y =rad * math.sin(value_of_theta) + Y_center

# sending the turtle up
TUR.up()
TUR.setpos(x,y)
TUR.down()
# directing our turtle
if nO > Start_draw_petaL-1:
PetaL(x,y)
else: TUR.stamp()```

#### Outer spiral and ending :

```#sketch and paint the petals
def PetaL( x, y ):
TUR.up()
TUR.setpos(x,y)
TUR.down()
TUR.begin_fill()
TUR.pen(outline=3,pencolor="black",fillcolor="blue")
TUR.right(25)
TUR.forward(100)
TUR.left(45)
TUR.forward(100)
TUR.left(130)
TUR.forward(100)
TUR.left(45)
TUR.forward(100)
TUR.up()
#for the last petal
TUR.end_fill()

TUR.shape("turtle")
#speed 0 is the fastest
TUR.speed(0)

#calling our function
Phy_patt( 200, 160, 137.508, 5, 10 )
#we're done!
TUR.exitonclick()```

All methods are on the main page of the Python turtle library.

Output section:

For more shapes,

```import turtle
turtle.getshapes()```

For TUR.shape(‘triangle’) the following output was received: