Skip to main content
Module

x/monke/mod.ts>Color

Get colors from image
Go to Latest
class Color
import { Color } from "https://deno.land/x/monke@v0.0.1/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

g: number

Green value of color

readonly
grayscale: Color

Convert to grayscale using luminosity

readonly
hex
readonly
hue

Calculate hue using chroma

readonly
invert
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
luminosity: number

Calculate luminosity

readonly
max: number

Get maximum of r, g, b

readonly
min: number

Get minimum of r, g, b

r: number

Red value of color

readonly
saturation

Get saturation

Methods

toJSON(): ColorData

Get a detailed conversion of the color.

toString(): string

Static Methods

toHex(n: number): string