UNPKG

@thi.ng/color

Version:

Array-based color types, CSS parsing, conversions, transformations, declarative theme generation, gradients, presets

84 lines 3.21 kB
import type { FnU, FnU2, NumericArray } from "@thi.ng/api"; import type { Color, ReadonlyColor } from "./api.js"; import type { CosGradientSpec, CosineGradientOpts, CosineGradientPreset } from "./api/gradients.js"; /** * Preset cosine gradient definitions. See previews at: * https://github.com/thi-ng/umbrella/tree/develop/packages/color#cosine-gradients * * @remarks * See http://dev.thi.ng/gradients/ for a gradient designer. Note: unlike the * linked original Clojure version, these presets here are for RGBA (though the * alpha channel is configured to always be 1.0) */ export declare const COSINE_GRADIENTS: Record<CosineGradientPreset, CosGradientSpec>; /** * Computes a single linear RGBA color for given gradient spec and normalized * position `t` (in `[0,1]` interval). * * @param spec - * @param t - */ export declare const cosineColor: (spec: CosGradientSpec, t: number) => Color; /** * Computes a full cosine gradient and returns an array of `n` sampled linear * RGBA colors. If the optional `tx` is given, each computed color will be * re-interpreted and/or transformed into another {@link Color} type. * * @remarks * For CSS/SVG use cases you could use {@link srgb} as transformation function * to not convert, but to reinterpret & wrap raw color values as SRGBA. * * @param n - * @param spec - * @param tx - */ export declare const cosineGradient: (n: number, spec: CosGradientSpec, tx?: FnU<Color>) => Color[]; /** * Similar to {@link cosineGradient}, but writes results into `buffer` from * given `offset` and component/element strides. Returns buffer. * * @remarks * Intended use case for this function: 1D texturemap/tonemap generation, e.g. * for dataviz etc. Also see {@link multiColorGradientBuffer}. * * @param n - number of colors * @param spec - gradient spec * @param buffer - target buffer/array * @param offset - start index (default: 0) * @param cstride - channel stride (default: 1) * @param estride - element stride (default: 4) */ export declare const cosineGradientBuffer: (n: number, spec: CosGradientSpec, buffer?: NumericArray, offset?: number, cstride?: number, estride?: number) => NumericArray; /** * Returns coefficients to produce a cosine gradient between the two * given RGBA colors. * * @param from - start color * @param to - end color */ export declare const cosineCoeffs: FnU2<ReadonlyColor, CosGradientSpec>; /** * Multi-color cosine gradient generator using linear RGBA color stops. Returns * an array of `n+1` linear RGBA color samples. * * @remarks * See [`tween`](https://docs.thi.ng/umbrella/transducers/functions/tween.html) * * @example * ```ts tangle:../export/cosine-gradient.ts * import { multiCosineGradient, srgb } from "@thi.ng/color"; * * multiCosineGradient({ * num: 10, * // gradient stops (normalized positions) * stops: [[0.1, [1, 0, 0, 1]], [0.5, [0, 1, 0, 1]], [0.9, [0, 0, 1, 1]]], * // optional color transform/coercion * tx: srgb * }) * ``` * * @param num - number of color steps to produce * @param stops - gradient stops */ export declare const multiCosineGradient: (opts: CosineGradientOpts) => Color[]; //# sourceMappingURL=cosine-gradients.d.ts.map