1 hidden cell
A flower
A sunflower
1 hidden cell
Phyllotaxis: draw flowers using mathematics
📖 Background
Mathematics can describe many phenomena of the natural world. Excellent examples are the shape of snowflakes, the fractal geometry of Romanesco broccoli, and how self-similarity rules the growth of plants. In this competition, you will design floral patterns using scatter plots!
You don't need any mathematical background to participate in this competition, but if you want to know more about phyllotaxis, you can check out this article on Wikipedia.
💾 The (sample) data
In this competition, you will create scatter plots in two dimensions, representing flower petals. You'll generate a dataset with two variables; let's call them x and y.
To get you started, Here are 44 points in a circle with radius 1. As every (x, y) point should be in the unit circle, it follows that x² + y² = 1. You can get this using the super famous Pythagorean trigonometric identity which states that sin²(θ) + cos²(θ) = 1 for any real number θ.
1 hidden cell
🏆 The Golden Ratio & The Golden Angle
Plants can arrange their leaves in spirals. A spiral is a curve which starts from the origin and moves away from the origin as it revolves around it. In the plot above all our points are the same distance from the origin. A simple way to arrange them in a spiral is to multiply x and y by a factor which increases for each point. You could use t as that factor, as it meets these conditions, but you could do something more harmonious, e.g. the Golden Angle:
Golden Angle = π(3 − √5)
Both the Golden Ratio and the Golden Angle appear in unexpected places in nature. Apart of flower petals and plant leaves, you'll find them in seed heads, pine cones, sunflower seeds, shells, spiral galaxies, hurricanes, etc.
-------- some addition here ---------
The golden ratio, or perfect ratio in a painting, is not exactly the center (ratio=0.5) but slightly off center, deviding the painting in the larger part being 0.618 or
Let's give it easy names:
- The larger part of your painting is 0.618 = big part
- The smaller part of your painting is 0.382 = small part
The larger part devided by the smaller part is the golden ratio 1.618 (or
The golden angle thus arises since a full circle is 2π and we multiply it with the small part of the painting yielding π(3 − √5) or
-------- Why are they special ---------
Some fun operations to see the beaty of the numbers that arrange under the rule
let's multiply the small part and the big part with or devide it and call those the power of
| ratio | big part | small part | power of |
|---|---|---|---|
| 0.236 | 0.146 | -3 | |
| 0.382 | 0.236 | -2 | |
| 0.618 | 0.382 | -1 | |
| 1 | 0.618 | 0 | |
| 1.618 | 1 | 1 | |
| 2.618 | 1.618 | 2 | |
| 4.236 | 2.618 | 2 |
What is 1 - 0.236? it's 0.764 or that number that we multiply
Funny don't you think?
| spiral galaxy | A sunflower | Hurricane | seashell | stock market |
|---|---|---|---|---|
# Let's create a more complex flower pattern by modifying the angle and incorporating color and transparency
# Define the number of points
points = 1000
# Define the Golden Angle in radians to create a phyllotaxis pattern
angle = np.pi * (3 - np.sqrt(5))
# Generate values
t = np.arange(0, points) * angle
r = np.sqrt(np.arange(0, points)) # The radius is defined to spread out the points
x = r * np.cos(t)
y = r * np.sin(t)
# Creating the plot
plt.figure(figsize=(8, 8))
plt.scatter(x, y, c=t, cmap='hsv', alpha=0.6, edgecolors='none')
# Remove axes
plt.axis('off')
plt.show()
Regardless of the power of phi you choose, it's congruent to the original flower the notebook started with
# Define the number of points
points = 618
# Define the Golden Angle
angle = np.pi * (3 - np.sqrt(5))
angle2 = np.pi * ((np.sqrt(5) - 1))
angle3 = np.pi * ((np.sqrt(5) + 1))
angle4 = np.pi * 2 * (((np.sqrt(5) + 1)/2)**2)
# Generate values for each spiral
t = np.arange(1, points + 1)
df = pd.DataFrame({
'xt': np.sin(t * angle) * t * angle,
'xt2': np.sin(t * angle2) * t * angle2,
'xt3': np.sin(t * angle3) * t * angle3,
'xt4': np.sin(t * angle4) * t * angle4,
'yt': np.cos(t * angle) * t * angle,
'yt2': np.cos(t * angle2) * t * angle2,
'yt3': np.cos(t * angle3) * t * angle3,
'yt4': np.cos(t * angle4) * t * angle4
})
fig, axes = plt.subplots(1,4,figsize=(24,6))
sns.scatterplot(data=df, x='xt',y='yt', c=t * angle, cmap='winter',ax=axes[0]).set(title='The 0.382 Fibonacci (original) spiral')
sns.scatterplot(data=df, x='xt2',y='yt2', c=t * angle2, cmap='spring',ax=axes[1]).set(title='The 0.618 Fibonacci spiral')
sns.scatterplot(data=df, x='xt3',y='yt3', c=t * angle3, cmap='summer',ax=axes[2]).set(title='The 1.618 Fibonacci spiral')
sns.scatterplot(data=df, x='xt4',y='yt4', c=t * angle4, cmap='autumn',ax=axes[3]).set(title='The 2.618 Fibonacci spiral')
for ax in fig.axes:
plt.sca(ax)
plt.axis('off');