Skip to main content
Module

x/monke/mod.ts>Color

Color quantization and dithering in TypeScript.
Go to Latest
class Color
import { Color } from "https://deno.land/x/monke@v0.0.4/mod.ts";

General class for RGBA colors

Constructors

new
Color(hex: string)

Construct a color from hex code

new
Color(
r: number,
g: number,
b: number,
a?: number,
)

Construct a color from rgba values

new
Color(
rOrHex: number | string,
g?: number,
b?: number,
a?,
)

Properties

a: number

Alpha (opacity) of color

readonly
average

Get the average of all colors Can also be used instead of grayscale using

const color = new Color(r, g, b, a);
const avg = color.average;
const grayscaleColor = new Color(avg, avg, avg, a);
b: number

Blue value of color

readonly
chroma

Calculate chroma

readonly
cmyk:
[
number,
number,
number,
number,
]
g: number

Green value of color

readonly
grayscale: Color

Convert to grayscale using luminance

readonly
hcg: [number, number, number]
readonly
hex
readonly
hsl: [number, number, number]

Hue, Saturation, Lightness

readonly
hsv: [number, number, number]

Hue, Saturation, Value

readonly
hue

Calculate hue using chroma

readonly
invert
readonly
lab: [number, number, number]

CIE Lab color space

readonly
lightness

Get lightness of image. Can also be used instead of grayscale using

const color = new Color(r, g, b, a);
const l = color.lightness * 255;
const grayscaleColor = new Color(l, l, l, a);
readonly
linearRgb

Get linear rgb values

readonly
luminance: number

Calculate luminance

readonly
max: number

Get maximum of r, g, b

readonly
min: number

Get minimum of r, g, b

readonly
perceivedLightness: number

Get perceived lightness

r: number

Red value of color

readonly
saturation

Get saturation

readonly
xyz: [number, number, number]

CIE 1931 XYZ

Methods

contrast(that: Color): number

Get contrast ratio

toJSON(): ColorData

Get a detailed conversion of the color.

toString(): string

Static Methods

toHex(n: number): string