ratio: Adaptive Aspect Ratio Transformation
Dimension-aware coordinate scaling for consistent proportions
The ratio function applies adaptive transformations based on dimensional relationships between coordinate spaces and target sizes. It automatically selects appropriate scaling strategies depending on whether the target space is wider or taller.
Adaptive Scaling Logic
Given coordinates and size vector :
When width ≥ height (landscape orientation):
When height > width (portrait orientation):
The selection between these modes uses:
Mathematical Foundation
Aspect Case | Primary Scaling | Secondary Offset | Unchanged Axis |
---|---|---|---|
Wide format | X-axis stretch | X-axis centering | Y-axis preserved |
Tall format | Y-axis stretch | Y-axis centering | X-axis preserved |
Live Editor
const fragment = () => { const adapted = ratio(uv, iResolution.xy) const waveform = adapted.x.mul(adapted.y).mul(20).sin().abs() const pattern = waveform.pow(adapted.length()) return vec4(vec3(pattern), 1) }