Color
A color in DisplayScript is a record with r, g, and b fields representing the red, green, and blue components of the color.
var green = { r: 0, g: 1, b: 0 } draw fill(green)
Each field has a range of zero (no contribution from this color) to one (full contribution from this color).
DisplayScript colors are represented in linear space, so you can add their components without gamma correction. They will be converted to sRGB before being drawn.
Most programs represent colors in sRGB (or something close to it). Use the srgb function to specify sRGB colors:
var srgbOrange = srgb(1, 0.5, 0) var linearOrange = { r: 1, g: 0.5, b: 0 } draw at(0, 0, @width, @height / 2, fill(srgbOrange)) draw at(0, @height / 2, @width, @height / 2, fill(linearOrange))
You can use the gray function to create a gray color (in linear space):
draw fill(gray(0.2))
DisplayScript colors do not have an alpha channel. Use the opacity function to do alpha blending.
draw at(50, 50, 100, 100, opacity(0.5, fill(srgb(1, 0.5, 0)))) draw at(100, 100, 100, 100, opacity(0.5, fill(srgb(1, 0.5, 1))))
Embarrassingly, alpha blending is done on sRGB components right now, so it's not gamma correct. As far as I can tell, this is a limitation of CoreGraphics (which we're using to draw everything at the moment).