UNPKG

pencil.js

Version:

Nice modular interactive 2D drawing library.

162 lines (161 loc) 4.63 kB
/** * Color class * @class */ export default class Color { /** * Return an instance from a generic definition * @param {ColorDefinition} colorDefinition - Any valid color definition (see constructor) * @return {Color} */ static from(...colorDefinition: string | number | number[] | Color): Color; /** * @typedef {Color|String|Number|Array<Number>} ColorDefinition */ /** * Color constructor * @param {ColorDefinition} colorDefinition - Many types accepted (other Color instance, color name, hex string, hex number, red/green/blue/alpha value) * @example * new Color("indigo"); // Any valid CSS color name * new Color("#123456"); // Hex string definition * new Color("#123"); // Hex shorthand string definition, #123 <=> #112233 * new Color(0x123456); // Hex number definition * new Color(0.1, 0.2, 0.3); // Red, Green, Blue definition * Every definition can have one more optional parameter for alpha (opacity) * new Color("violet", 0.5); */ constructor(...colorDefinition: string | number | number[] | Color); /** * Create a new copy of this color * @return {Color} */ clone(): Color; /** * Set the red channel * @param {Number} value - New value */ set red(value: number); /** * Get the red channel value * @return {Number} */ get red(): number; /** * Set the green channel * @param {Number} value - New value */ set green(value: number); /** * Get the green channel value * @return {Number} */ get green(): number; /** * Set the blue channel * @param {Number} value - New value */ set blue(value: number); /** * Get the blue channel value * @return {Number} */ get blue(): number; /** * Set the transparency channel * @param {Number} value - New value */ set alpha(value: number); /** * Get the transparency channel value * @return {Number} */ get alpha(): number; /** * Return an array with red, green and blue value * @example [0.1, 0.2, 0.3] * @return {Array<Number>} */ get array(): number[]; /** * Return hexadecimal rgb notation * @example "#123456" * @return {String} */ get hex(): string; /** * Return hexadecimal rgb notation * @example "#123456" * @return {String} */ get rgb(): string; /** * Return the closest CSS color name * @example "aliceblue" * @return {String} */ get name(): string; /** * Change this values * @param {ColorDefinition} colorDefinition - Any supported color definition (see constructor) * @return {Color} Itself */ set(...colorDefinition: string | number | number[] | Color): Color; /** * Change to its greyscale value * @return {Color} Itself */ grey(): Color; /** * Change hue value (0 = red, 0.5 = blue, 1 = red, 1.5 = blue ...) * @param {Number} value - Any value between 0 and 1 * @return {Color} Itself */ hue(value: number): Color; /** * Change saturation value (0 = grey, 1 = pure color) * @param {Number} value - Any value between 0 and 1 * @return {Color} Itself */ saturation(value: number): Color; /** * Change lightness value (0 = black, 0.5 = pure color, 1 = white) * @param {Number} value - Any value between 0 and 1 * @return {Color} Itself */ lightness(value: number): Color; /** * Invert the color value * @return {Color} Itself */ reverse(): Color; /** * Restrict the color space to an amount of possible value * @param {Number} number - Number of allowed value * @return {Color} Itself */ level(number: number): Color; /** * Change the color toward another color * @param {ColorDefinition} colorDefinition - Any other color * @param {Number} ratio - Ratio of distance to move (0 = no change, 0.5 = equal mix, 1 = same as target color) * @return {Color} Itself */ lerp(colorDefinition: string | number | number[] | Color, ratio: number): Color; /** * @return {String} */ toString(): string; /** * Return a json ready array * @return {Array<Number>} */ toJSON(): Array<number>; gray: () => Color; mix: (colorDefinition: string | number | number[] | Color, ratio: number) => Color; [parsedKey]: any; } /** * @module Color */ declare const parsedKey: unique symbol; export {};