Color Class
Color is Alia's built-in color class, used to represent and process color data. It supports creating and converting colors in multiple formats.
Creating Colors
The constructor accepts (color, type) by position, and array-style calls pass arguments in the order of the formal parameters. type defaults to 'Hex'.
const hexColor = new Color ['#FF5733', 'Hex']
const nameColor = new Color ['red', 'Name']
const rgbArray = [255, 87, 51]
const rgbColor = new Color [rgbArray, 'Rgb']
const oklchArray = [0.6, 0.2, 30]
const oklchColor = new Color [oklchArray, 'Oklch']
const defaultColor = new Color ['#00FF00']
Static Methods
Color.set
Registers a custom color name, after which the color can be referenced via new Color ['registered-name', 'Name']. If the registered name matches a highlighting category (Keyword, Variable, KeyArgument, Alias, Type, etc.), it overrides that category's default color during code highlighting.
Syntax:
Color.set <String name> to <Color color>
Example:
Color.set 'Accent' to new Color ['#FF00FF', 'Hex']
const accent = new Color ['Accent', 'Name']
print accent.to 'Hex'
print accent.to 'Rgb'
Color.set 'Keyword' to new Color ['#FF0000', 'Hex']
Supported Color Types
| Type | Format | Example |
|---|---|---|
| Name | String | 'red', 'blue', 'white' |
| Hex | String | '#FF5733', '#00FF00' |
| Rgb | Array | [255, 87, 51] |
| Oklch | Array | [0.6, 0.2, 30] |
Instance Properties
raw
Returns the raw value of the color.
const color = new Color ['#FF5733', 'Hex']
print color.raw ~ outputs '#FF5733'
type
Returns the type of the color.
const color = new Color ['red', 'Name']
print color.type ~ outputs 'Name'
Instance Methods
to
Converts the color to the specified type. Returns the raw value of the target type.
const color = new Color ['#FF5733', 'Hex']
const rgb = color.to 'Rgb'
print rgb
const oklch = color.to 'Oklch'
print oklch
const hex = color.to 'Hex'
print hex
toString
Converts the color to its string representation. Zero-argument methods are invoked via call.
const color = new Color ['#FF5733', 'Hex']
print call color.toString ~ outputs 'Color Color(Hex: "#FF5733")'
valueOf
Returns the raw value of the color. Zero-argument methods are invoked via call.
const color = new Color ['#FF5733', 'Hex']
print call color.valueOf ~ outputs '#FF5733'
Supported Color Names
In addition to the built-in color names below, custom color names can be registered via Color.set.
Basic Colors
white- Whiteblack- Blackred- Redgreen- Greenblue- Blueyellow- Yellowcyan- Cyanmagenta- Magenta
Extended Colors
orange- Orangepurple- Purplepink- Pinkgray/grey- Graybrown- Brownnavy- Navy blueteal- Tealolive- Olivemaroon- Maroon
Other Colors
aquamarine- Aquamarinecoral- Coralcrimson- Crimsongold- Goldindigo- Indigokhaki- Khakilavender- Lavenderlime- Limesalmon- Salmonsilver- Silvertan- Tanturquoise- Turquoiseviolet- Violetwheat- Wheat
Color Conversion Examples
Format Conversion
const hex = new Color ['#FF5733', 'Hex']
const rgb = hex.to 'Rgb'
const back = new Color [rgb, 'Rgb']
const hexBack = back.to 'Hex'
print rgb
print hexBack
Chained Conversion
const blue = new Color ['blue', 'Name']
print blue.to 'Hex'
print blue.to 'Rgb'
print blue.to 'Oklch'
Example Code
const hexColor = new Color ['#FF5733', 'Hex']
const nameColor = new Color ['coral', 'Name']
const rgbArray = [255, 127, 80]
const rgbColor = new Color [rgbArray, 'Rgb']
print call hexColor.toString
print call nameColor.toString
print call rgbColor.toString
print 'Raw value: ' .. hexColor.raw
print 'Color type: ' .. hexColor.type
const hexToRgb = hexColor.to 'Rgb'
print 'Hex to RGB: ' .. hexToRgb
const hexToOklch = hexColor.to 'Oklch'
print 'Hex to Oklch: ' .. hexToOklch
const red = new Color ['red', 'Name']
print 'Red Hex: ' .. (red.to 'Hex')
print 'Red RGB: ' .. (red.to 'Rgb')
const fromRgbArray = [255, 87, 51]
const fromRgb = new Color [fromRgbArray, 'Rgb']
print 'RGB to Hex: ' .. (fromRgb.to 'Hex')
const oklchArray = [0.6, 0.2, 30]
const oklchColor = new Color [oklchArray, 'Oklch']
print 'Oklch to RGB: ' .. (oklchColor.to 'Rgb')
print 'Oklch to Hex: ' .. (oklchColor.to 'Hex')
const color1 = new Color ['#FF5733', 'Hex']
const color2 = new Color ['orange', 'Name']
const rgb1 = color1.to 'Rgb'
const rgb2 = color2.to 'Rgb'
print 'Color 1 RGB: ' .. rgb1
print 'Color 2 RGB: ' .. rgb2
const colorNames = ['red', 'green', 'blue', 'coral', 'gold']
each name in colorNames {
const color = new Color [name, 'Name']
print name .. ': ' .. (color.to 'Hex')
}