Colors
import "lumen:color"
The color module builds colors for use when drawing to the screen. Lumen comes with a small named palette for convenience, and four ways to make your own.
Ranges
Red, green, and blue run 0-255. Alpha runs 0-1.
The two ranges are deliberately different. A single range accepting both and guessing from the value cannot tell 1 (nearly transparent) from 1.0 (fully opaque), and gets it silently wrong either way.
Creating Colors
color.rgb()
Takes red, green, and blue between 0 and 255, plus an optional alpha between 0 and 1. color.rgba() is the same method under a second name.
color.rgb(255, 128, 0) // opaque orange
color.rgb(255, 128, 0, 0.5) // the same orange at half opacity
color.hex()
Parses a hex string, with or without the leading #. Accepts #rgb, #rgba, #rrggbb, and #rrggbbaa.
color.hex('#fff')
color.hex('#ff8800')
color.hex('#ff8800cc')
Note that in hex form the alpha channel is a byte like the others — the 0-1 range applies to rgb() and withAlpha().
color.hsl()
Takes a hue in degrees (0-360), a saturation and a lightness between 0 and 1, and an optional alpha between 0 and 1.
color.hsl(30, 1, 0.5) // the same orange
color.hsl(30, 1, 0.5, 0.5)
hsl is the convenient one for generating a spread of related colors — walk the hue and keep saturation and lightness fixed.
Color Methods
Colors are objects, and carry methods of their own.
| Method | Returns |
|---|---|
getRed() | The red channel, 0-255. |
getGreen() | The green channel, 0-255. |
getBlue() | The blue channel, 0-255. |
getAlpha() | The alpha, 0-1. |
toHex() | The color as a hex string. |
withAlpha(a) | A copy of the color at the given opacity, 0-1. |
lerp(other, amount) | A color between this one and other, at amount from 0 to 1. |
shadow = color.black.withAlpha(0.25)
flash = game.baseColor.lerp(color.white, 0.6)
lerp is how a health bar goes green to red, or a sprite flashes white on a hit.
Built-in Palette
color.blackcolor.whitecolor.transparentcolor.redcolor.greencolor.bluecolor.yellowcolor.orangecolor.purplecolor.cyancolor.magentacolor.browncolor.graycolor.lightGraycolor.darkGrayThese are here to keep prototypes readable before a game settles on its own palette — not a suggestion that a game should ship with them.