LittleJS 1.28.0

Engine

Color

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

Constructor

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

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:1129

Returns this color expressed in hsla format

isValid() → booleanengineMath.js:1227

Checks if this is a valid color

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

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:1069

Returns a copy of this color times the color passed in

c Color

other color

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

Returns a new color that has each component randomly adjusted

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

Returns this color expressed as 32 bit RGBA value

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

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:1022

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:1040

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:1186

Set this color from a hex code

hex string

html hex code

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

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:1064

Returns a copy of this color minus the color passed in

c Color

other color

toString(useAlpha) → stringengineMath.js:1173

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:1054

Returns a copy of this color with the alpha set

a number optional, default 1

alpha