flowerSDF: Parametric Flower Distance Field
Organic Petal Generation through Polar Mathematics
The flowerSDF
function creates flower-like shapes with configurable petal count using polar coordinate transformations. This 2D distance field generates smooth, organic forms through cosine modulation of angular components.
Mathematical Foundation
The flower shape emerges from polar coordinate manipulation:
where:
- represents the radial distance from center
- gives the angular position
- controls the number of petals
The cosine modulation creates regular undulations in the radial function, forming petal structures. The absolute value ensures positive petal formation, while the scaling factors control shape smoothness.
Function Signature
Parameter | Type | Description |
---|---|---|
st | vec2 | 2D coordinate position |
N | int | Number of flower petals |
Implementation Demonstrations
Live Editor
const fragment = () => { const petalCount = int(iTime.mul(2).sin().mul(3).add(6)) const dist = flowerSDF(uv, petalCount) const inside = dist.step(0) const edge = float(0.02).smoothstep(0, dist.abs()) const color = inside.mul(0.9).add(edge.mul(0.6)) return vec4(color.mul(vec3(1, 0.7, 0.8)), 1) }