Skip to content

Instantly share code, notes, and snippets.

@CGArtPython
Created October 3, 2022 06:44
Show Gist options
  • Save CGArtPython/d3fa0359ec09f31cc47cc9da73ad511e to your computer and use it in GitHub Desktop.
Save CGArtPython/d3fa0359ec09f31cc47cc9da73ad511e to your computer and use it in GitHub Desktop.
Phyllotaxis pattern experiment based on code from https://www.youtube.com/watch?v=WHAQwhr1Jto
"""
Creating a phyllotaxis pattern based on formula 4.1 from
http://algorithmicbotany.org/papers/abop/abop-ch4.pdf
"""
# give Python access to Blender's functionality
import bpy
# extend Python functionality to generate random numbers
import random
# extend Python's math functionality
import math
def phyllotaxis_pattern(count, angle, ico_sphere_radius, scale_fac):
for n in range(count):
# calculate "φ" in formula (4.1) http://algorithmicbotany.org/papers/abop/abop-ch4.pdf
current_angle = n * angle
# calculate "r" in formula (4.1) http://algorithmicbotany.org/papers/abop/abop-ch4.pdf
current_radius = scale_fac * math.sqrt(n)
# convert from Polar Coordinates (r,φ) to Cartesian Coordinates (x,y)
x = current_radius * math.cos(current_angle)
y = current_radius * math.sin(current_angle)
# place ico sphere
bpy.ops.mesh.primitive_circle_add(radius=ico_sphere_radius, location=(x, y, 0))
count = 400
ico_sphere_radius = 0.5
# "c" in formula (4.1) http://algorithmicbotany.org/papers/abop/abop-ch4.pdf
scale_fac = 1.0
# "α" angle in radians in formula (4.1) http://algorithmicbotany.org/papers/abop/abop-ch4.pdf
# angle = math.radians(random.uniform(137.0, 138.0))
# set angle to the Fibonacci angle 137.5 to get the sunflower pattern
angle = math.radians(137.5)
phyllotaxis_pattern(count, angle, ico_sphere_radius, scale_fac)
angle = math.radians(137.0)
phyllotaxis_pattern(count, angle, ico_sphere_radius, scale_fac)
angle = math.radians(138.0)
phyllotaxis_pattern(count, angle, ico_sphere_radius, scale_fac)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment