Skip to main content
Module

x/monke/mod.ts>Color

Color quantization and dithering in TypeScript.
Latest
class Color
Re-export
import { Color } from "https://deno.land/x/monke@v1.0.2/mod.ts";

General class for RGBA colors

Constructors

new
Color(hex: string)

Construct a color from hex code

new
Color(hex: number)

Construct a color from hex number

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

fromCmyk(
c: number,
m: number,
y: number,
k: number,
): Color
fromHex(hex: string): Color
fromHsl(
h: number,
s: number,
l: number,
): Color
fromHsv(
h: number,
s: number,
v: number,
): Color
fromLab(
l: number,
a: number,
b: number,
): Color
fromRgba(
r: number,
g: number,
b: number,
): Color

Redundant static method for conversion from sRGB color space

fromXyz(
x: number,
y: number,
z: number,
): Color

Convert from CIE XYZ color space

toHex(n: number): string