Qu

rgba

Builtin index · Plotting

result = rgb(r, g, b, [scale=])

Input: r, g, b, scale · Output: result

What it is

Builds a colour from channel numbers: r, g, b (and, for rgba, a fourth channel a). The channels are 0–255 bytes (rgb(128, 192, 255)) -- always, whatever the values look like: rgb(0.5, 0.75, 1.0) is the byte colour #010101. For 0–1 fractions pass scale = 1 or scale = "normalized" (rgb(0.5, 0.75, 1.0, scale = 1) is #80bfff); scale = 255 is the default spelled out. A fourth channel of at most 1 is an opacity, otherwise a byte.

Overloads

rgba(r, g, b, a) reads its fourth channel a two different ways depending on its own magnitude, so the same call can be written either the "raw byte" way or the CSS "opacity fraction" way and land on the same colour.

2 forms. Each carries its own inputs, outputs and worked example — pick the tab for the one you are calling.

CodeInputOutputDescription
result = rgb(r, g, b, [scale=])
r numberBuilds a colour from channel numbers: r, g, b (and, for rgba, a fourth channel a).
g numberBuilds a colour from channel numbers: r, g, b (and, for rgba, a fourth channel a).
b numberBuilds a colour from channel numbers: r, g, b (and, for rgba, a fourth channel a).
scale number, optionalscale = 255 is the default spelled out.
result string
Written as a whole number sharing the other three channels' 0–255 range, a is read as a raw alpha byte.

Examples

Written for this form and run by the build -- the output below is what the engine actually produced.

print(rgba(255, 0, 0, 128))   # "#ff000080" -- half-transparent red, byte alpha

output
#ff000080
CodeInputOutputDescription
result = rgb(r, g, b, [scale=])
r numberThe boundary sits at 1: rgba(r, g, b, 1) is read as the fraction (fully opaque), never as the barely-visible byte value 1.
g numberThe boundary sits at 1: rgba(r, g, b, 1) is read as the fraction (fully opaque), never as the barely-visible byte value 1.
b numberThe boundary sits at 1: rgba(r, g, b, 1) is read as the fraction (fully opaque), never as the barely-visible byte value 1.
scale number, optionalscale = 255 is the default spelled out.
result string
Written as a number 0–1 instead, a is read as an opacity fraction — the CSS convention — so 0.5 here lands on the exact same byte as 128 above.

Examples

Written for this form and run by the build -- the output below is what the engine actually produced.

print(rgba(255, 0, 0, 0.5))   # "#ff000080" -- the same colour, from the CSS-style opacity fraction

output
#ff000080

See also

rgb — documented in the same entry.