Home

Module colour

Lua bindings to interact with colours. An example would be:
 col1 = colour.new( "Red" ) -- Get by name
 col2 = colour.new( 0.5, 0.5, 0.5, 0.3 ) -- Create with RGB values
 col3 = colour.new() -- White by default
 col2:setHSV( col1:hsv() ) -- Set colour 2 with colour 1's HSV values
 

Functions

colour.__eq (c1, c2) Compares two colours to see if they are the same.
colour.alpha (col) Gets the alpha of a colour.
colour.hsv (col) Gets the HSV values of a colour.
colour.new (r, g, b, a) Gets a colour.
colour.rgb (col) Gets the RGB values of a colour.
colour.setAlpha (col, alpha) Sets the alpha of a colour.
colour.setHSV (col, h, s, v) Sets the colours values from the HSV colourspace.
colour.setRGB (col, r, g, b) Sets the colours values from the RGB colourspace.


Functions

colour.__eq (c1, c2)
Compares two colours to see if they are the same.

Parameters

  • c1: Colour 1 to compare.
  • c2: Colour 2 to compare.

Return value:

true if both colours are the same.
colour.alpha (col)
Gets the alpha of a colour. Value is from from 0. (transparent) to 1. (opaque).

Parameters

  • col: Colour to get alpha of.

Usage:

colour_alpha = col:alpha()

Return value:

The alpha of the colour.
colour.hsv (col)
Gets the HSV values of a colour. Values are from 0. to 1.

Parameters

  • col: Colour to get HSV values of.

Usage:

h,s,v = col:rgb()

Return value:

The hue, saturation and value values of the colour.
colour.new (r, g, b, a)
Gets a colour.

Parameters

  • r: Red value of the colour.
  • g: Green value of the colour.
  • b: Blue value of the colour.
  • a: Alpha value of the colour.

Usage

  • colour.new( "Red" ) -- Gets colour by name
  • colour.new( "Red", 0.5 ) -- Gets colour by name with alpha 0.5
  • colour.new() -- Creates a white (blank) colour
  • colour.new( 1., 0., 0. ) -- Creates a bright red colour
  • colour.new( 1., 0., 0., 0.5 ) -- Creates a bright red colour with alpha 0.5

Return value:

A newly created colour.
colour.rgb (col)
Gets the RGB values of a colour. Values are from 0. to 1.

Parameters

  • col: Colour to get RGB values of.

Usage:

r,g,b = col:rgb()

Return value:

The red, green and blue values of the colour.
colour.setAlpha (col, alpha)
Sets the alpha of a colour. Value is from 0. (transparent) to 1. (opaque).

Parameters

  • col: Colour to set alpha of.
  • alpha: Alpha value to set.

Usage:

col:setAlpha( 0.5 ) -- Make colour half transparent
colour.setHSV (col, h, s, v)
Sets the colours values from the HSV colourspace. Values are from 0. to 1.

Parameters

  • col: Colour to set HSV values.
  • h: Hue value to set.
  • s: Saturation value to set.
  • v: Value to set.

Usage:

col:setHSV( h, s, v )
colour.setRGB (col, r, g, b)
Sets the colours values from the RGB colourspace. Values are from 0. to 1.

Parameters

  • col: Colour to set RGB values.
  • r: Red value to set.
  • g: Green value to set.
  • b: Blue value to set.

Usage:

col:setRGB( r, g, b )

Valid XHTML 1.0!