LittleJS 1.30.1

Engine

Color

Color object (red, green, blue, alpha) with some helpful functions

Constructor

new Color(r, g, b, a)engineMath.js:1057

Create a color with the rgba components passed in, white by default

r number optional, default 1

red

g number optional, default 1

green

b number optional, default 1

blue

a number optional, default 1

alpha

let a = new Color;              // white
let b = new Color(1, 0, 0);     // red
let c = new Color(0, 0, 0, 0);  // transparent black
let d = rgb(0, 0, 1);         // blue using rgb color
let e = hsl(.3, 1, .5);         // green using hsl color

Members

Methods

Members

Alpha

Blue

Green

Red

Methods

Returns a copy of this color plus the color passed in

c Color

other color

Returns a copy of this color clamped to the valid range between 0 and 1

Returns a new color that is a copy of this

Returns a copy of this color divided by the color passed in

c Color

other color

HSLA() → [number, number, number, number]engineMath.js:1190

Returns this color expressed in hsla format

isValid() → booleanengineMath.js:1288

Checks if this is a valid color

lerp(c, percent) → ColorengineMath.js:1152

Returns a new color that is p percent between this and the color passed in, percent is clamped to 0-1

c Color

other color

percent number
multiply(c) → ColorengineMath.js:1130

Returns a copy of this color times the color passed in

c Color

other color

mutate(amount, alphaAmount) → ColorengineMath.js:1218

Returns a new color that has each component randomly adjusted

amount number optional, default 0.05
alphaAmount number optional, default 0
rgbaInt() → numberengineMath.js:1276

Returns this color expressed as 32 bit RGBA value

scale(scale, alphaScale) → ColorengineMath.js:1141

Returns a copy of this color scaled by the value passed in, alpha can be scaled separately

scale number
alphaScale number optional, default scale
set(r, g, b, a) → ColorengineMath.js:1083

Sets values of this color and returns self

r number optional, default 1

red

g number optional, default 1

green

b number optional, default 1

blue

a number optional, default 1

alpha

setAlpha(a) → ColorengineMath.js:1101

Sets the alpha of this color and returns self

a number optional, default 1

alpha

Sets this color from another color and returns self

c Color

other color

setHex(hex) → ColorengineMath.js:1247

Set this color from a hex code

hex string

html hex code

setHSLA(h, s, l, a) → ColorengineMath.js:1170

Sets this color given a hue, saturation, lightness, and alpha

h number optional, default 0

hue

s number optional, default 0

saturation

l number optional, default 1

lightness

a number optional, default 1

alpha

subtract(c) → ColorengineMath.js:1125

Returns a copy of this color minus the color passed in

c Color

other color

toString(useAlpha) → stringengineMath.js:1234

Returns this color expressed as a hex color code

useAlpha boolean optional, default true

if alpha should be included in result

withAlpha(a) → ColorengineMath.js:1115

Returns a copy of this color with the alpha set

a number optional, default 1

alpha