Module:Rgba/doc
Jump to navigation
Jump to search
This is the documentation page for Module:Rgba
Module:Rgba requires Module:LibraryUtil.
Module:Rgba is required by Module:Chart data.
This module is a helper module to be used by other modules; it may not designed to be invoked directly. See RuneScape:Lua/Helper modules for a full list and more information.
Function | Type | Use |
---|---|---|
new( red, [green|0], [blue|0], [alpha|1] ) new( hex ) | number/string, number/nil, number/nil, number/nil | Returns a new rgba object. Values red , green and blue are in the range 0-255; alpha is 0-1. It is also possible to give a hex string e.g. #112233 or #11223344 .
When converted to a string with tostring( rgba ) it will return a string in the form rgba(r,b,g,a) where r, g, b and a are filled in with numbers. |
rgba:lighten( val ) | number | Returns a new rgba object with its brightness changed. 1 is no change, 0 is complete black, 2 is double brightness, 1.1 is 10% more, 0.5 is halve, etc. |
rgba:darken( val ) | number | Returns a new rgba object with its brightness changed. 1 is no change, 0 is complete white, 2 is halve brightness, 1.1 is 10% darker, 0.5 is double brightness, etc. |
rgba:hueRotate( num ) | number | Returns a new rgba object with its hue num degrees rotated. Decimal values are allowed. |
rgba:saturate( val ) | number | Returns a new rgba object with its saturation changed. 1 is no change, 0 is greyscale, 2 is double saturation, 1.5 is 50% more, etc. |
rgba:fade( val ) | number | Returns a new rgba object with its alpha value set to val . val is clipped to the range 0-1. |
rgba:clone() | N/A | Returns a copy with the same values. |
Example:
local rgba = require( 'Module:Rgba' )
local color1 = rgba.new( 126, 20, 6 )
mw.log( color1 ) --> 'rgba(126,20,6,1)'
mw.log( color1:lighten( 1.3 ) ) --> 'rgba(164,26,8,1)'
mw.log( color1:darken( 1.3 ) ) --> 'rgba(97,15,5,1)'
mw.log( color1:hueRotate( 50 ) ) --> 'rgba(126,120,6,1)'
mw.log( color1:saturate( 1.1 ) ) --> 'rgba(132,15,0,1)'
mw.log( color1:fade( 0.3 ) ) --> 'rgba(126,20,6,0.3)'
local color2 = color1:lighten( 1.3 ):saturate( 1.1 ) -- Operations can be chained
mw.log( color2 ) --> 'rgba(172,20,0,1)'
mw.log( color1 ) --> 'rgba(126,20,6,1)' color1 is unchanged