Module:Rgba/doc

This is the current revision of this page, as edited by Alex (talk | contribs) at 18:23, 15 October 2024 (Created page with "{{Documentation}} {{Helper module |name = Rgba |fname1 = <nowiki>new( red, [green|0], [blue|0], [alpha|1] )</nowiki>;; <nowiki>new( hex )</nowiki> |ftype1 = number/string, number/nil, number/nil, number/nil |fuse1 = Returns a new rgba object. Values <code>red</code>, <code>green</code> and <code>blue</code> are in the range 0-255; <code>alpha</code> is 0-1. It is also possible to give a hex string e.g. <code>#112233</code> or <code>#11223344</code>...."). The present address (URL) is a permanent link to this version.

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This is the documentation page for Module:Rgba

This is a documentation subpage for Module:Rgba.
It contains usage information, categories, and other content that is not part of the original module page.
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.

FunctionTypeUse
new( red, [green|0], [blue|0], [alpha|1] )
new( hex )
number/string, number/nil, number/nil, number/nilReturns 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 )numberReturns 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 )numberReturns 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 )numberReturns a new rgba object with its hue num degrees rotated. Decimal values are allowed.
rgba:saturate( val )numberReturns 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 )numberReturns a new rgba object with its alpha value set to val. val is clipped to the range 0-1.
rgba:clone()N/AReturns 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