
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Phyllotaxis pattern in Python?
What is phyllotaxis pattern?
When we go back, in our botany classes and the plant world, phyllotaxis means the arrangement of flowers, leaves or seeds on a plant stem, similar to the one found in Fibonacci spiral. Based on Fibonacci sequence, the Fibonacci spiral is a set of numbers that follows a pattern similar on pascal’s triangle. The Fibonacci sequence numbers are something like - 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, etc. So the Fibonacci sequence number is the sum of its previous numbers.
Fibonacci spirals
We generally look for symmetry and patterns to understand the objects around us. Without realizing it our eyes are seeing the Fibonacci sequences, or in the case of a sunflower head, a Fibonacci spiral.
Solution
Sunflower spiral
Example Code
import math import turtle def PhyllotacticPattern( t, petalstart, angle = 137.508, size = 2, cspread = 4 ): """print a pattern of circles using spiral phyllotactic data""" # initialize position turtle.pen(outline=1,pencolor="black",fillcolor="orange") # turtle.color("orange") phi = angle * ( math.pi / 180.0 ) xcenter = 0.0 ycenter = 0.0 # for loops iterate in this case from the first value until < 4, so for n in range (0,t): r = cspread * math.sqrt(n) theta = n * phi x = r * math.cos(theta) + xcenter y = r * math.sin(theta) + ycenter # move the turtle to that position and draw turtle.up() turtle.setpos(x,y) turtle.down() # orient the turtle correctly turtle.setheading(n * angle) if n > petalstart-1: #turtle.color("yellow") drawPetal(x,y) else: turtle.stamp() def drawPetal( x, y ): turtle.up() turtle.setpos(x,y) turtle.down() turtle.begin_fill() #turtle.fill(True) turtle.pen(outline=1,pencolor="black",fillcolor="yellow") turtle.right(25) turtle.forward(100) turtle.left(45) turtle.forward(100) turtle.left(140) turtle.forward(100) turtle.left(45) turtle.forward(100) turtle.up() turtle.end_fill() # this is needed to complete the last petal turtle.shape("turtle") turtle.speed(0) # make the turtle go as fast as possible PhyllotacticPattern( 200, 160, 137.508, 4, 10 ) turtle.exitonclick() # lets you x out of the window when outside of idle
Solution
With a small change in your above program, you result could be displaced something like (give custom color and alter some values):
- Related Articles
- Unix filename pattern matching in Python
- Pattern matching in Python with Regex
- Find and Replace Pattern in Python
- How to print pattern in Python?
- Python ā Cross Pattern Pairs in List
- Unix filename pattern matching in Python (fnmatch)
- Python - Increasing alternate element pattern in list
- Increasing alternate element pattern in list in Python
- Unix style pathname pattern expansion in Python (glob)
- Pattern After Double, Reverse, and Swap in Python
- How to match pattern over multiple lines in Python?
- Python program to print matrix in a snake pattern
- Python Program to print the pattern āGā
- Python Program to Print all the Pattern that Matches Given Pattern From a File
- Program to enclose pattern into bold tag in Python?\n
