Color¶
Reference¶
- class Color¶
- module:
Represents an RGBA color with optional HSV support and common color utilities.
Values r, g, b range from 0 to 255, a from 0 to 1. Includes math operators and static color constants.
- static new(r, g, b, a?)¶
Create a new color
- set(r, g, b, a?)¶
Set the color components
- Parameters:¶
r (
number
) – Red (0–255)g (
number
) – Green (0–255)b (
number
) – Blue (0–255)a? (
number
) – Alpha (0–1)
- toData()¶
Returns a table representing the color
- lerp(a, b, t)¶
Linearly interpolate between two colors
- toHsv()¶
Convert RGB to HSV
- setFromHsv(h, s, v)¶
Set color from HSV values
- Parameters:¶
h (
number
) – Hue (0–360)s (
number
) – Saturation (0–1)v (
number
) – Value (0–1)
- clamp()¶
Clamp color values to valid ranges.
r, g, b are clamped to [0, 255]; a is clamped to [0, 1]
- toHex()¶
Convert the color to a hexadecimal string (ignores alpha).
- static fromHex(hex)¶
Create a Color from a hexadecimal string
- premultiplyAlpha()¶
Premultiply RGB values by alpha (in-place).
Useful for certain rendering pipelines.
- invert()¶
Invert the color (in-place).
Alpha is not changed.