segmentFrame
A frame along the line between two position props: how far each pixel is along it and across it.
segmentFrame(slots: {from: PropRef; to: PropRef}): (params: GpuFragmentParams, surface: { uv: Expr; aspect: Expr; }) => SegmentFrame
Import frames from shaders/std and use frames.segmentFrame.
Pass {from: p('from'), to: p('to')} and call the result with params and a surface. along is 0 at from and equals length at to. across is the signed distance from the line. All three are aspect-corrected, in canvas-height units.
Parameters
| Name | Type | Notes |
|---|---|---|
slots | {from: PropRef; to: PropRef} |
Example
const {along, across, length} = segmentFrame({from: p('from'), to: p('to')})(params, surfaceOf(params))
Tip. Divide
alongbylengthfor a 0–1 position along the line, the natural gradient parameter.
See also
centredFrame— A frame centred on a position prop: each pixel's offset from the centre and its distance.directionFrame— The two axes of a direction given in degrees, for patterns that run along it.surfaceOf— The canvas a generator paints on: itsuv, itsviewportsize in pixels and itsaspect.