Skip to content

Colour

Type

Colour

Represents an RGBA colour. Note that colour each component is an 8-bit integer (ie. must be between 0 and 255).

Constants

Name Value
FORMAT_RGB 0
FORMAT_RGBA 1
FORMAT_HEX 2
FORMAT_ZDOOM 3

Properties

Property Type Description
r integer Red component
g integer Green component
b integer Blue component
a integer Alpha component (transparency)
fr float Red component as a float (0.0-1.0)
fg float Green component as a float (0.0-1.0)
fb float Blue component as a float (0.0-1.0)
fa float Alpha component as a float (0.0-1.0)

Constructors

Colour.new()

Creates a new colour with all components set to 0.


Colour.new(r, g, b)

Creates a new colour with the given r, g and b components. The a component is set to 255.

Parameters

  • r (integer): Red component (0 - 255)
  • g (integer): Green component (0 - 255)
  • b (integer): Blue component (0 - 255)

Colour.new(r, g, b, a)

Creates a new colour with the given r, g, b and a components.

Parameters

  • r (integer): Red component (0 - 255)
  • g (integer): Green component (0 - 255)
  • b (integer): Blue component (0 - 255)
  • a (integer): Alpha component (0 - 255)

Functions

Overview

Conversion

AsHSL() -> float, float, float AsLAB() -> float, float, float AsString(format) -> string FromHSL(hue, saturation, lightness)


AsHSL

Gets the colour in HSL colourspace.

Returns

  • float: The hue value (0.0 - 1.0)
  • float: The saturation value (0.0 - 1.0)
  • float: The lightness value (0.0 - 1.0)

AsLAB

Gets the colour in CIELAB colourspace.

Returns

  • float: The lightness value (0.0 - 1.0)
  • float: The green-red value (0.0 - 1.0)
  • float: The blue-yellow value (0.0 - 1.0)

AsString

Gets a string representation of the colour in the specified format.

Parameters

  • format (integer): The format of the string representation. See FORMAT_ constants above

Returns

  • string: The colour as a string of the specified format

Example

local colour = Colour.new(100, 150, 200, 150)

App.LogMessage(colour:AsString(Colour.FORMAT_RGB))   -- rgb(100, 150, 200)
App.LogMessage(colour:AsString(Colour.FORMAT_RGBA))  -- rgba(100, 150, 200, 150)
App.LogMessage(colour:AsString(Colour.FORMAT_HEX))   -- #6496C8
App.LogMessage(colour:AsString(Colour.FORMAT_ZDOOM)) -- "64 96 C8"

FromHSL

Sets the colour from the given HSL colourspace values.

Parameters

  • hue (float): The hue value to set (0.0 - 1.0)
  • saturation (float): The saturation value to set (0.0 - 1.0)
  • lightness (float): The lightness value to set (0.0 - 1.0)