-
Notifications
You must be signed in to change notification settings - Fork 0
ColourClass
Lightens or darkens a colour by a given amount.
The amount
parameter defaults to 30. The lighten
parameter defaults
to true.
Parameters
-
rgb
(table
) - The RGB colour as a table with three elements: red, green, and blue. -
amount
(number?
) - The amount to adjust the colour by. -
lighten
(boolean?
) - Whether to lighten (true) or darken (false) the colour.
Returns
table
- The adjusted RGB colour as a table with three elements: red, green, and blue.
Examples
colour.adjust_colour({100,100,100},50, true)
-- {150, 150, 150}
Adjusts the saturation of a colour by a given factor.
The factor
parameter defaults to 0.5.
Parameters
-
rgb
(table
) - The RGB colour as a table with three elements: red, green, and blue. -
factor
(number?
) - A factor between 0 (fully desaturated) and 1 (fully saturated).
Returns
table
- The adjusted RGB colour as a table with three elements: red, green, and blue.
Examples
colour.adjust_saturation({35,50,100}, 0.5)
-- {48, 55, 80}
Generates the analogous colours of a given colour. The analogous colours are generated by rotating the hue of the given colour by a given angle.
The angle
parameter defaults to 30.
Parameters
-
rgb
(table
) - The RGB colour as a table with three elements: red, green, and blue. -
angle
(number?
) - The angle to separate the analogous colours by.
Returns
table
- A table of RGB colours that are analogous to the given colour.
Examples
colour.analogous({100,100,100})
-- { { 70, 100, 100 }, { 100, 100, 100 }, { 130, 100, 100 } }
Returns the complementary colour of a given colour.
Parameters
-
rgb
(table
) - The RGB colour as a table with three elements: red, green, and blue.
Returns
table
- The complementary RGB colour as a table with three elements: red, green, and blue.
Examples
colour.complementary({150,150,150})
-- {105, 105, 105}
Calculates the contrasting colour based on the luminance of a given colour.
Parameters
-
rgb
(table
) - The RGB colour as a table with three elements: red, green, and blue.
Returns
table
- The contrasting colour as a table with three elements: red, green, and blue.
Examples
colour.contrast({100,100,100})
-- {0, 0, 0}
Calculates the contrast ratio between two colours.
Parameters
-
rgb1
(table
) - The first RGB colour as a table with three elements: red, green, and blue. -
rgb2
(table
) - The second RGB colour as a table with three elements: red, green, and blue.
Returns
number
- The contrast ratio between the two colours.
Examples
colour.contrast_ratio({100,100,100}, {0,0,0})
-- 12.0
Darkens a colour by a given amount.
Parameters
-
rgb
(table
) - The RGB colour as a table with three elements: red, green, and blue. -
amount
(number?
) - The amount to darken the colour by.
Returns
table
- The darkened RGB colour as a table with three elements: red, green, and blue.
Examples
colour.darken({100,100,100},50)
-- {50, 50, 50}
Converts a colour to its grayscale equivalent.
Parameters
-
rgb
(table
) - The RGB colour as a table with three elements: red, green, and blue.
Returns
table
- The grayscale RGB colour as a table with three elements: red, green, and blue.
Examples
colour.grayscale({35,50,100})
-- {62, 62, 62}
Converts an HSL colour to an RGB colour.
Parameters
-
hsl
(table
) - The HSL colour as a table with three elements: hue, saturation, and lightness.
Returns
table
- The RGB colour as a table with three elements: red, green, and blue.
Examples
colour.hsl_to_rgb({180, 50, 50})
-- {127, 127, 127}
Interpolates between two RGB colours based on a step value. Functionally, it takes two colours and returns a third colour somewhere between the two colours, based on the step value. Generally used to fade between two colours. The step value is the current transition percentage as a whole number between the two colours, with 0 being the first colour and 100 being the second colour.
Available interpolation methods are:
linear
-
smooth
(default) smoother
ease_in
ease_out
Parameters
-
rgb1
(table
) - The first RGB colour as a table with three elements: red, green, and blue. -
rgb2
(table
) - The second RGB colour as a table with three elements: red, green, and blue. -
factor
(number
) - The step value between 0 and 1. -
method
(string?
) - The interpolation method to use.
Returns
table
- The interpolated RGB colour as a table with three elements: red, green, and blue.
Examples
colour.interpolate({255, 0, 0}, {0, 0, 255}, 50)
-- {127, 0, 127}
Determines if a colour is a light colour. The colour is considered light if the luminance is greater than 0.5.
Parameters
-
rgb
(table
) - The RGB colour as a table with three elements: red, green, and blue.
Returns
boolean
- True if the colour is light, false otherwise.
Examples
colour.is_light({255, 255, 255})
-- true
Lightens a colour by a given amount.
The amount
parameter defaults to 30.
Parameters
-
rgb
(table
) - The RGB colour as a table with three elements: red, green, and blue. -
amount
(number?
) - The amount to lighten the colour by.
Returns
table
- The lightened RGB colour as a table with three elements: red, green, and blue.
Examples
colour.lighten({100,100,100},50)
-- {150, 150, 150}
Lightens or darkens the first colour by a given amount based only a comparison with the second colour. If the colours are already contrasting, the original colour is returned.
The amount
parameter defaults to 30.
Parameters
-
rgb_colour
(table
) - The first RGB colour as a table with three elements: red, green, and blue. -
rgb_compare
(table
) - The second RGB colour as a table with three elements: red, green, and blue. -
amount
(number?
) - The amount to darken the colour by.
Returns
table
- The darkened RGB colour as a table with three elements: red, green, and blue.
Examples
colour.lighten_or_darken({100,100,100}, {255,255,255}, 50)
-- {100, 100, 100}
Generates a series of monochromatic colours based on a given colour.
The steps
parameter defaults to 5.
Parameters
-
rgb
(table
) - The RGB colour as a table with three elements: red, green, and blue. -
steps
(number?
) - The number of variations to generate.
Returns
table
- A table of RGB colours that are monochromatic variations of the given colour.
Examples
colour.monochrome({ 100, 100, 100 })
-- { { 100, 100, 100 }, { 100, 100, 100 }, { 100, 100, 100 } }
Generates a random RGB colour.
Returns
table
- A random RGB colour as a table with three elements: red, green, and blue.
Examples
colour.random()
-- { 123, 45, 67 }
Generates a random shade of a given colour within a range.
The range
parameter defaults to 50.
Parameters
-
rgb
(table
) - The RGB colour as a table with three elements: red, green, and blue. -
range
(number?
) - The range to adjust the colour by (e.g., 50 means +/- 50 for R, G, and B).
Returns
table
- A random RGB colour that is a shade of the given colour.
Examples
colour.random_shade({100,100,100}, 50)
-- {150, 150, 150}
Converts an RGB colour to an HSL colour.
Parameters
-
rgb
(table
) - The RGB colour as a table with three elements: red, green, and blue.
Returns
table
- The HSL colour as a table with three elements: hue, saturation, and lightness.
Examples
colour.rgb_to_hsl({255, 255, 255})
-- {0, 0, 100}
Generates the split complement colours of a given colour.
The angle
parameter defaults to 30.
Parameters
-
rgb
(table
) - The RGB colour as a table with three elements: red, green, and blue. -
angle
(number?
) - The angle to separate the split complement colours by.
Returns
table
- A table of RGB colours that are the split complement of the given colour.
Examples
colour.split_complement({100,100,100})
-- { { 15, 204, 204 }, { 100, 204, 204 } }
Generates the tetrad colours of a given colour.
Parameters
-
rgb
(table
) - The RGB colour as a table with three elements: red, green, and blue.
Returns
table
- A table of RGB colours that are the tetrad of the given colour.
Examples
colour.tetrad({100,100,100})
-- { { 100, 100, 100 }, { 100, 100, 100 }, { 100, 100, 100 }, { 100, 100, 100 } }
Converts an RGB colour to a hex string. Whether the hex string includes a
background colour depends on the include_background
parameter. This
parameter defaults to false.
Parameters
-
rgb
(table
) - The RGB colour as a table with three elements: red, green, and blue. -
include_background
(boolean?
) - Whether to include a background colour.
Returns
string
- The hex string.
Examples
colour.to_hex({255, 255, 255})
-- "#ffffff"
Generates the triad colours of a given colour. Does not return the original colour, but two returned colours that are considered tritones of the original colour.
Parameters
-
rgb
(table
) - The RGB colour as a table with three elements: red, green, and blue.
Returns
table
- A table of RGB colours that are the triad of the given colour.
Examples
colour.triad({100,100,100})
-- { { 15, 204, 204 }, { 100, 204, 204 } }
Documentation generated with Gludoc.