Three.js Fibonacci Spiral & Golden Angle Phyllotaxis
Golden-ratio phyllotaxis in Three.js — grow a sunflower head, pinecone and sphere from the 137.5° golden angle, color the Fibonacci parastichies, and build the golden-rectangle spiral.
Key topics: three.js fibonacci, golden ratio, golden angle, phyllotaxis, sunflower, parastichy, math in nature
Game Over
What this code does
- Vogel's Model: seed n is placed at radius c·√n and angle n × 137.508°, which packs seeds with no gaps.
- Golden Angle Sensitivity: nudge the divergence angle by a few hundredths of a degree and the spirals turn into spokes and gaps.
- Parastichies: coloring seeds by n mod 21, 34 or 55 picks out the visible spiral families, which are always Fibonacci numbers.
- Other Forms: the same rule wraps onto a sphere (Fibonacci lattice) and a pinecone-like ellipsoid.
- Golden Rectangles: Fibonacci-sized squares are attached counter-clockwise, and each holds a quarter arc of the spiral.
- Controls: form, seed count, divergence angle, spacing, parastichy coloring, growth and replay.
Related Demos
Continue Learning
JavaScript Implementation
const scene = new THREE.Scene()
const camera = new THREE.PerspectiveCamera(45, width / height, 0.1, 200)
camera.position.set(0, 22, 20)
camera.lookAt(0, 0, 0)
const renderer = new THREE.WebGLRenderer({ antialias: true })
renderer.setSize(width, height)
document.querySelector('#app').appendChild(renderer.domElement)
scene.add(new THREE.HemisphereLight(0xfff7e6, 0x332211, 1.4))
// Vogel's sunflower model: r = c·√n, θ = n × 137.508°
const count = 1600
const golden = THREE.MathUtils.degToRad(180 * (3 - Math.sqrt(5)))
const seeds = new THREE.InstancedMesh(new THREE.SphereGeometry(1, 12, 8), new THREE.MeshStandardMaterial(), count)
const m = new THREE.Matrix4()
const color = new THREE.Color()
for (let i = 0; i < count; i++) {
const r = 0.32 * Math.sqrt(i)
const theta = i * golden
m.makeScale(0.18, 0.18, 0.18).setPosition(Math.cos(theta) * r, 0, Math.sin(theta) * r)
seeds.setMatrixAt(i, m)
seeds.setColorAt(i, color.setHSL((i % 21) / 21, 0.75, 0.55)) // 21 parastichies
}
scene.add(seeds)
renderer.render(scene, camera)