Color

Summary

An RGB color

Class Properties

NameReturn TypeDescription

black

Color Read-only

The color black

blue

Color Read-only

The color blue

cyan

Color Read-only

The color cyan

gray

Color Read-only

The color gray

green

Color Read-only

The color green

grey

Color Read-only

The color grey

magenta

Color Read-only

The color magenta

red

Color Read-only

The color red

white

Color Read-only

The color white

yellow

Color Read-only

The color yellow

Instance Properties

NameReturn TypeDescription

this[index]

number Read/Write

The color component at the specified index

r

number Read-only

The red component

g

number Read-only

The green component

b

number Read-only

The blue component

a

number Read-only

The alpha component

grayscale

number Read-only

The grayscale value

gamma

Color Read-only

The gamma color space representation

linear

Color Read-only

The linear color space representation

maxColorComponent

number Read-only

The maximum color component value

html

string Read-only

The HTML hex string of the color (for example "A4D0FF")

greyscale

number Read-only

The grayscale value

hsv

Vector3 Read-only

The hue, saturation and brightess

Class Methods

Color:New(r, g, b)

Creates a new instance of a color with the specified RGB values

Returns: Color (instance of the Color)

Parameters:

NameTypeDefaultDescription

r

number

0

The red component of the color. Default is 0

g

number

0

The green component of the color. Default is 0

b

number

0

The blue component of the color. Default is 0

Example

myColor = Color:New(0.5, 0, 1)

Color:New(html)

Creates a new instance of the Color with the color parsed from the specified HTML string

Returns: Color (Returns the color. Invalid html inputs return bright magenta (r=1, g=0, b=1))

Parameters:

NameTypeDefaultDescription

html

string

The HTML string representing the color

Example

myColor = Color:New("D3B322")

Color:Lerp(a, b, t)

Performs a linear interpolation between two colors

Returns: Color (The interpolated color)

Parameters:

NameTypeDefaultDescription

a

The start color

b

The end color

t

number

The interpolation value. Should be between 0 and 1

Example

newColor = Color:Lerp(color1, color2, 0.5)

Color:LerpUnclamped(a, b, t)

Performs a linear interpolation between two colors without clamping the interpolation parameter

Returns: Color (color)

Parameters:

NameTypeDefaultDescription

a

The start color

b

The end color

t

number

The interpolation value

Example

newColor = Color:Lerp(color1, color2, 1.5)

Color:HsvToRgb(h, s, v)

Converts an HSV color to an RGB color

Returns: Color (color)

Parameters:

NameTypeDefaultDescription

h

number

The hue value. Should be between 0 and 1

s

number

The saturation value. Should be between 0 and 1

v

number

The value value. Should be between 0 and 1

Example

newColor = Color:HsvToRgb(0.5, 0.9, 0.5)

Color:HsvToRgb(hsv)

Converts an HSV Vector3 to an RGB color

Returns: Color (color)

Parameters:

NameTypeDefaultDescription

hsv

A Vector3 with xyz representing hsv. All values between 0 and 1

Example

newColor = Color:HsvToRgb(myHsv)

Instance Methods

color:Add(other)

Adds the specified color to this color

Returns: Color (color)

Parameters:

NameTypeDefaultDescription

other

The color to add

Example

newColor = color1:Add(color2)

color:Add(r, g, b)

Adds the specified RGB values to this color

Returns: Color (color)

Parameters:

NameTypeDefaultDescription

r

number

The red component value to add

g

number

The green component value to add

b

number

The blue component value to add

Example

newColor = color1:Add(0.5, 0, 0.1)

color:Subtract(other)

Subtracts the specified color from this color

Returns: Color (color)

Parameters:

NameTypeDefaultDescription

other

The color to subtract

Example

newColor = color1:Subtract(color2)

color:Subtract(r, g, b)

Subtracts the specified RGB values from this color

Returns: Color (color)

Parameters:

NameTypeDefaultDescription

r

number

The red component value to subtract

g

number

The green component value to subtract

b

number

The blue component value to subtract

Example

newColor = color1:Subtract(0.5, 0.25, 0)

color:Multiply(value)

Multiplies this color by the specified value

Returns: Color (color)

Parameters:

NameTypeDefaultDescription

value

number

The value to multiply

Example

newColor = color1:Multiply(0.5)

color:Multiply(r, g, b)

Multiplies this color by the specified RGB values

Returns: Color (color)

Parameters:

NameTypeDefaultDescription

r

number

The red component value to multiply

g

number

The green component value to multiply

b

number

The blue component value to multiply

Example

newColor = color1:Multiply(0.85, 0, 0)

color:Divide(value)

Divides this color by the specified value

Returns: Color (color)

Parameters:

NameTypeDefaultDescription

value

number

The value to divide

Example

newColor = color1:Divide(0.5)

color:NotEquals(other)

Determines whether this color is not equal to the specified color

Returns: boolean (true if this color is not equal to the specified color; otherwise, false)

Parameters:

NameTypeDefaultDescription

other

The color to compare

Example

if color1:NotEquals(color2) then print("colors are different") end

color:NotEquals(r, g, b)

Determines whether this color is not equal to the specified RGB values

Returns: boolean (true if this color is not equal to the specified RGB values; otherwise, false)

Parameters:

NameTypeDefaultDescription

r

number

The red component value to compare

g

number

The green component value to compare

b

number

The blue component value to compare

Example

if color1:NotEquals(0, 1, 0) then print("color is not green") end

Last updated