kochSDF: Koch Snowflake Fractal Distance Field
Iterative Fractal Boundary Generation through Recursive Subdivision
The kochSDF
function generates the Koch snowflake fractal, a classic example of self-similar geometric structures. Through iterative subdivision and transformation, it constructs the characteristic spiky boundary pattern that defines this mathematical fractal.
Mathematical Foundation
The Koch snowflake construction follows a recursive subdivision process:
where represents the transformation that replaces each line segment with four segments arranged in a triangular spike pattern. The transformation matrix:
The distance calculation involves iterative coordinate transformations:
where and the width scaling factor .
Function Variants
Function | Parameters | Description |
---|---|---|
kochSDF | st , center , N | Full parameterization with center and iteration count |
kochSDFSimple | st , N | Simplified version with default center at (0.5, 0.5) |
Implementation Demonstrations
ライブエディター
const fragment = () => { const pos = uv.sub(0.5) const dist = kochSDF(pos.add(0.5), vec2(0.5), int(10)) const inside = dist.step(0) const edge = float(0.005).smoothstep(0, dist.abs()) const color = inside.mul(0.9).add(edge.mul(0.7)) return vec4(color.mul(vec3(0.2, 0.8, 1)), 1) }