/** * A Gradient object representing a linear or radial gradient fill. * Created via {@link Renderer#createLinearGradient} or {@link Renderer#createRadialGradient}. * Can be passed to {@link Renderer#setColor} as a fill style. */ export class Gradient { /** * @param {"linear"|"radial"} type - the gradient type * @param {number[]} coords - gradient coordinates [x0, y0, x1, y1] for linear, [x0, y0, r0, x1, y1, r1] for radial */ constructor(type: "linear" | "radial", coords: number[]); type: "linear" | "radial"; /** * Add a color stop to the gradient. * @param {number} offset - value between 0.0 and 1.0 * @param {Color|string} color - a CSS color string or Color object * @returns {Gradient} this gradient for chaining * @example * gradient.addColorStop(0, "#FF0000"); * gradient.addColorStop(0.5, "green"); * gradient.addColorStop(1, "blue"); */ addColorStop(offset: number, color: Color | string): Gradient; /** * Get or create a native `CanvasGradient` for use with a 2D context. * * This is the one to reach for when baking a gradient into your own * canvas — it hands back a value for `ctx.fillStyle` and touches no * shared state, so two callers cannot clobber each other. * * The result is cached and reused until a stop changes. * @param {CanvasRenderingContext2D} context - the 2D context to create the gradient on * @returns {CanvasGradient} a native gradient bound to that context * @example * // bake a gradient into a standalone canvas * const c = document.createElement("canvas"); * c.width = 64; c.height = 64; * const ctx = c.getContext("2d"); * ctx.fillStyle = myGradient.toCanvasGradient(ctx); * ctx.fillRect(0, 0, 64, 64); */ toCanvasGradient(context: CanvasRenderingContext2D): CanvasGradient; /** * Get the interpolated color at a given position along the gradient. * Useful for procedural effects like trails that need per-segment colors. * @param {number} position - position along the gradient (0.0–1.0) * @param {Color} out - output Color object to write into * @returns {Color} the output Color object * @example * const gradient = new Gradient("linear", [0, 0, 1, 0]); * gradient.addColorStop(0, "#ff0000"); * gradient.addColorStop(1, "#0000ff"); * gradient.getColorAt(0.5, myColor); // myColor is now purple */ getColorAt(position: number, out: Color): Color; /** * Release pooled resources held by this gradient. */ destroy(): void; } import CanvasRenderTarget from "./rendertarget/canvasrendertarget.js"; import type { Color } from "../math/color.ts"; //# sourceMappingURL=gradient.d.ts.map