Mathematical Constants for Creative Coding
Mathematical Foundation
Mathematical constants form the foundation of algorithmic visual art. These universal values appear repeatedly in natural patterns, geometric relationships, and visual effects. TSL provides immediate access to essential constants without manual calculation.
The fundamental mathematical constants are defined as:
Additional derived constants include:
- Golden angle: radians
- Half-pi:
- Square root of two:
Core Constants Library
Constant | Value | Application |
---|---|---|
PI | 3.14159... | Circle geometry, wave functions |
TAU | 6.28318... | Full circle rotations |
PHI | 1.61803... | Golden ratio proportions |
EPSILON | 0.0000001 | Floating point comparisons |
Circle and Wave Mathematics
PI
and TAU
constants enable precise circular motion and wave calculations. TAU
represents a complete circle rotation, eliminating the need for 2 * PI
calculations.
ライブエディター
const fragment = () => { const angle = iTime.mul(TAU) // Complete rotation per time unit const wave = angle.mul(4).sin() // Four waves per rotation const radius = wave.mul(0.3).add(0.5) const x = angle.cos().mul(radius) const y = angle.sin().mul(radius) const color = vec3(x.add(0.5), y.add(0.5), wave.add(1).mul(0.5)) return vec4(color, 1) }
Golden Ratio Aesthetics
PHI
and GOLDEN_RATIO
constants create naturally pleasing proportions. The golden angle creates spiral patterns found in nature.
ライブエディター
const fragment = () => { const center = vec2(0.5) const pos = uv.sub(center) const radius = pos.length() const angle = pos.y.atan2(pos.x).add(iTime.mul(0.2)) const spiral = angle.div(GOLDEN_ANGLE).fract() const color1 = vec3(spiral, radius.mul(2), 1) const color2 = vec3(1, spiral.mul(PHI.fract()), radius) const finalColor = color1.mix(color2, iTime.sin().mul(0.5).add(0.5)) return vec4(finalColor, 1) }