website is under construction
Lumen

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.

MethodReturns
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

Black
#000000
RGB: 0, 0, 0
color.black
White
#FFFFFF
RGB: 255, 255, 255
color.white
Transparent
#00000000
RGB: 0, 0, 0 at alpha 0
color.transparent
Red
#E03C3C
RGB: 224, 60, 60
color.red
Green
#48B860
RGB: 72, 184, 96
color.green
Blue
#4080E0
RGB: 64, 128, 224
color.blue
Yellow
#F0C848
RGB: 240, 200, 72
color.yellow
Orange
#E88838
RGB: 232, 136, 56
color.orange
Purple
#9660D0
RGB: 150, 96, 208
color.purple
Cyan
#48C8D0
RGB: 72, 200, 208
color.cyan
Magenta
#D858A8
RGB: 216, 88, 168
color.magenta
Brown
#805838
RGB: 128, 88, 56
color.brown
Gray
#808080
RGB: 128, 128, 128
color.gray
Light Gray
#C0C0C0
RGB: 192, 192, 192
color.lightGray
Dark Gray
#404040
RGB: 64, 64, 64
color.darkGray

These are here to keep prototypes readable before a game settles on its own palette — not a suggestion that a game should ship with them.