import { Expr, GpuFragmentParams } from '../../gpu/contract'; import { PropRef } from '../values'; /** * The props of a grid layout: `columns` and `rows` (counts), `gapX` and `gapY` (fractions of * the canvas width and height), `stagger` (0 to 1, shifts every other row by that much of a * cell) and `flip`, a compile-time select that mirrors alternate cells (`'none'`, * `'alternate-flip-x'`, `'alternate-flip-y'`, `'both'`). */ export interface GridSlots { columns: PropRef; rows: PropRef; gapX: PropRef; gapY: PropRef; stagger: PropRef; /** A compile-time select: `'none'`, `'alternate-flip-x'`, `'alternate-flip-y'` or `'both'`. */ flip: PropRef; } /** * The props of a radial layout: `count`, `radius` (a fraction of the canvas height), * `startAngle` and `sweep` (degrees), and `faceCenter`, a boolean that turns each copy to face * the middle of the circle. */ export interface RadialSlots { count: PropRef; radius: PropRef; startAngle: PropRef; sweep: PropRef; faceCenter: PropRef; } /** * The props of a line layout: `count`, `direction` (degrees, 0 points right) and `spacing` * between copies (a fraction of the canvas height). */ export interface LineSlots { count: PropRef; direction: PropRef; spacing: PropRef; } /** One layout, built by `grid`, `radial` or `line`. */ export type PlacementSpec = { kind: 'grid'; slots: GridSlots; } | { kind: 'radial'; slots: RadialSlots; } | { kind: 'line'; slots: LineSlots; }; /** * Copies in rows and columns, filling this layer's bounding box. * * Pass it as the recipe's `placement`, or as one member of `byMode`. * * @example * ```ts * placement: grid({columns: p('columns'), rows: p('rows'), gapX: p('gapX'), gapY: p('gapY'), stagger: p('stagger'), flip: p('flip')}) * ``` * @tip Mark `flip` `compileTime: true`. Only the chosen mirroring is compiled in. * @see radial, line, byMode */ export declare const grid: (slots: GridSlots) => PlacementSpec; /** * Copies around a circle centred on the layer inside. * * `sweep` at 360 spaces them evenly all the way round; smaller sweeps make an arc starting at * `startAngle`. * * @example * ```ts * placement: radial({count: p('count'), radius: p('radius'), startAngle: p('startAngle'), sweep: p('sweep'), faceCenter: p('faceCenter')}) * ``` * @see grid, line, byMode */ export declare const radial: (slots: RadialSlots) => PlacementSpec; /** * Copies in a row, marching away from the layer inside in one direction. * * @example * ```ts * placement: line({count: p('count'), direction: p('direction'), spacing: p('spacing')}) * ``` * @see grid, radial, byMode */ export declare const line: (slots: LineSlots) => PlacementSpec; /** A layout chosen by a select prop, built by `byMode`. */ export interface PlacementPick { mode: PropRef; members: { grid: PlacementSpec; radial: PlacementSpec; linear: PlacementSpec; }; } /** * Lets one select prop switch between a grid, a radial and a linear layout. * * `mode` is a compile-time select with the values `'grid'`, `'radial'` and `'linear'`; only * the chosen layout is compiled in. * * @example * ```ts * placement: byMode(p('mode'), {grid: grid({...}), radial: radial({...}), linear: line({...})}) * ``` * @see grid, radial, line */ export declare const byMode: (mode: PropRef, members: PlacementPick["members"]) => PlacementPick; /** * How each copy differs from the last. `scale` and `opacity` multiply with every copy (1 keeps * them equal), `rotation` adds per copy in radians (give the prop a degrees-to-radians * transform). The `jitter` props (0 to 1) add seeded randomness to position, rotation, scale * and opacity; `seed` re-rolls it. `phase` (0 to 1) slides the whole layout by one cell or one * copy and wraps seamlessly, for looping animation. */ export interface VariationSlots { scale: PropRef; rotation: PropRef; opacity: PropRef; jitter: { position: PropRef; rotation: PropRef; scale: PropRef; opacity: PropRef; }; seed: PropRef; /** Layout animation phase, 0 to 1; 1 is the same layout as 0. */ phase: PropRef; } /** Everything `repeatInstances` needs: what to copy, where to put the copies, and how they vary. */ export interface RepeatInstancesRecipe { /** Crop insets on the copied area, each a fraction (0 to 0.49) of its width or height. */ source: { crop: { left: PropRef; right: PropRef; top: PropRef; bottom: PropRef; }; }; placement: PlacementPick | PlacementSpec; variation: VariationSlots; /** Hue rotation added per copy, in radians. Off at 0; give the prop `recompile: crosses(0)`. */ hueShift?: PropRef; /** A compile-time select: `'forward'` stacks later copies on top, `'backward'` underneath. */ order: PropRef; } /** * Many copies of the layer inside, laid out and varied as the recipe says. * * Returns the fragment for `gpu.fragment` on a definition with `requiresRTT`, `requiresChild` * and `wantsBoundsParams` set. Copies stack with normal alpha in the recipe's `order`. The * result is straight alpha. * * @example * ```ts * gpu: {fragment: repeatInstances({source: {crop: {left: p('cropLeft'), right: p('cropRight'), top: p('cropTop'), bottom: p('cropBottom')}}, placement: radial({count: p('count'), radius: p('radius'), startAngle: p('startAngle'), sweep: p('sweep'), faceCenter: p('faceCenter')}), variation: {scale: p('instanceScale'), rotation: p('instanceRotation'), opacity: p('instanceOpacity'), jitter: {position: p('jitterPosition'), rotation: p('jitterRotation'), scale: p('jitterScale'), opacity: p('jitterOpacity')}, seed: p('seed'), phase: p('phase')}, hueShift: p('hueShift'), order: p('zOrder')})} * ``` * @tip `hueShift` costs nothing at 0. Give the prop `recompile: crosses(0)` so it switches on cleanly. * @see grid, radial, line, byMode */ export declare function repeatInstances(recipe: RepeatInstancesRecipe): (params: GpuFragmentParams) => Expr; //# sourceMappingURL=instances.d.ts.map