UNPKG

blaze-2d

Version:

A fast and simple WebGL 2 2D game engine written in TypeScript

98 lines (97 loc) 2.89 kB
/** * Stores the color values for a RGBA color. */ export interface RGBAColor { r: number; g: number; b: number; a?: number; } /** * A value that can be parsed by a {@link Color} instance. */ export declare type ColorLike = RGBAColor | string; /** * Represents a color value such as `rgba(255, 1, 100, 255)`, `#FEFEFE` or `lightblue` to allow for easy conversion between color representations */ export default class Color { original: string | RGBAColor; hex: string; rgba: RGBAColor; webgl: number[]; /** * Creates a {@link Color} instance from a {@link ColorLike} representation. * * @param color The {@link ColorLike} representation to use when creating the {@link Color} instance */ constructor(color: ColorLike); /** * Validates a rgba color. * * @param color The rgba color to validate * @returns Wether or not the `color` is a valid rgba color */ validateRGBA(color: RGBAColor): boolean; /** * Validates a hex color. * * @param color The hex color to validate * @returns Wether or not the `color` is a valid hex color */ validateHEX(color: string): boolean; /** * Validates a html color. * * @param color The html color to validate * @returns Wether or not the `color` is a valid html color */ validateHTML(color: string): boolean; /** * Takes in a rgba color then converts it to hex and webgl and stores the conversions. * * @param color The rgba color to parse */ parseRGBA(color: RGBAColor): void; /** * Takes in a hex color then converts it to rgba and webgl and stores the conversions. * * @param color The hex color to parse */ parseHEX(color: string): void; /** * Takes in a html color then converts it to hex, rgba and webgl and stores the conversions. * * @param color The html color to parse */ parseHTML(color: string): void; /** * Converts a valid hex color to rgba. * * @param hex The hex color to convert to rgba * @returns The rgba equivalent of the hex color * * @throws When an invalid hex color is provided */ hexToRgba(hex: string): RGBAColor; /** * Converts a valid rgba color to hex. * * @param rgba The rgba color to convert to hex * @returns The hex equivalent of the rgba color * * @throws When an invalid rgba color is provided */ rgbaToHex(rgba: RGBAColor): string; /** * Converts a valid rgba color to webgl. * * @param rgba The rgba color to convert to a webgl color representation * @returns The webgl equivalent of the rgba color * * @throws When an invalid rgba color is provided */ rgbaToWebGL(rgba: RGBAColor): number[]; html: { [index: string]: string; }; }