Skip to main content


8-bit sRGB color with transparency as 32 bits ordered RGBA

You can create a color at compile-time (meaning there's no parsing at runtime) using comptimeFromString:

const color = Color.comptimeFromString("#694200");

This means that if the color is wrong, a compile error will be thrown:

const color = Color.comptimeFromString("hello, world");

will throw during compile

error: 'hello, world' is not a valid color

You can also create a color at run-time using fromString, note that this function may throw an error (which can be error.NotSupported or error.InvalidLength).

Both functions only accept two syntaxes:

  • RGB hex (e.g. #694200 to get { .red = 0x69, .green = 0x42, .blue = 0x00 })
  • RGBA hex (e.g. #69420088 to get { .red = 0x69, .green = 0x42, .blue = 0x00, .alpha = 0x88 })

At last, a Color can be created by filling in the struct fields manually:

const color = Color { .red = 0x69, .green = 0x42, .blue = 0x00, .alpha = 0x88 };

Colors can be linearly interpolated using capy.lerp(colorA, colorB, t) or Color.lerp(colorA, colorB, t). The former is preferred.
Currently this interpolation happens in the sRGB color space, but this is subject to changes in the following versions.

Preset colors‚Äč

All the following colors can be accessed quickly using declarations (e.g. Color.maroon or

  • maroon (#800000)
  • red (#ff0000)
  • orange (#ffa500)
  • yellow (#ffff00)
  • lime (#00ff00)
  • green (#008000)
  • olive (#808000)
  • aqua (#00ffff)
  • teal (#008080)
  • blue (#0000ff)
  • navy (#000080)
  • fuchsia (#ff00ff)
  • purple (#800080)
  • black (#000000)
  • gray (#808080)
  • silver (#c0c0c0)
  • white (#ffffff)
  • transparent (#00000000)