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

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


Functions

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

Parameters:

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

Returns:

    boolean true if both colours are the same.
new (r, g, b[, a=1.])
Gets a colour. ( r, g, b, a )

Parameters:

  • r number Red value of the colour.
  • g number Green value of the colour.
  • b number Blue value of the colour.
  • a number Alpha value of the colour. (default 1.)

Returns:

    Colour A newly created 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
alpha (col)
Gets the alpha of a colour.

Value is from from 0. (transparent) to 1. (opaque). ( col )

Parameters:

  • col Colour Colour to get alpha of.

Returns:

    number The alpha of the colour.

Usage:

    colour_alpha = col:alpha()
rgb (col)
Gets the RGB values of a colour.

Values are from 0. to 1. ( col )

Parameters:

  • col Colour Colour to get RGB values of.

Returns:

  1. number The red value of the colour.
  2. number The green value of the colour.
  3. number The blue value of the colour.

Usage:

    r,g,b = col:rgb()
hsv (col)
Gets the HSV values of a colour.

Values are from 0. to 1. ( col )

Parameters:

  • col Colour Colour to get HSV values of.

Returns:

  1. number The hue of the colour.
  2. number The saturation of the colour.
  3. number The value of the colour.

Usage:

    h,s,v = col:rgb()
setRGB (col, r, g, b)
Sets the colours values from the RGB colourspace.

Values are from 0. to 1. ( col, r, g, b )

Parameters:

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

Usage:

    col:setRGB( r, g, b )
setHSV (col, h, s, v)
Sets the colours values from the HSV colourspace.

Values are from 0. to 1. ( col, h, s, v )

Parameters:

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

Usage:

    col:setHSV( h, s, v )
setAlpha (col, alpha)
Sets the alpha of a colour.

Value is from 0. (transparent) to 1. (opaque). ( col, alpha )

Parameters:

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

Usage:

    col:setAlpha( 0.5 ) -- Make colour half transparent
generated by LDoc 1.4.3 Last updated 2020-02-20 05:27:49