Skip to content
FutureBlitz

    Install

    Import std.math.color

    std.math.color

    Color and Color32. A Color is four Floats, linear RGB and alpha, for lighting and blending, where math on light is right; a Color32 is four bytes, sRGB and alpha, as images and screens keep them. They convert with sRGB's gamma both ways, so a Color32 made a Color and back is the bytes it was. Hex, HSV, and HSL colors are sRGB's, as CSS's are, with a hue from 0 to 1 around, and OKLab's are from linear RGB. Alpha is linear in both, and 1 or 255 unless it's given.

    std/math/color.fb

    Types

    Color32 struct

    Public Struct Color32 Implements Hashable, Printable

    Four bytes: sRGB red, green, and blue, and alpha, from 0 to 255.

    std/math/color.fb, line 11

    • Public Field r: UInt8 field #

      Its red, from 0 to 255.

    • Public Field g: UInt8 field #

      Its green, from 0 to 255.

    • Public Field b: UInt8 field #

      Its blue, from 0 to 255.

    • Public Field a: UInt8 field #

      Its alpha, from 0, transparent, to 255, opaque.

    • Public Static Property Transparent: Color32 property #

      No color at all: transparent black.

    • Public Static Property Black: Color32 property #

      Black.

    • Public Static Property White: Color32 property #

      White.

    • Public Static Property Gray: Color32 property #

      Gray, half way between black and white.

    • Public Static Property Red: Color32 property #

      Red.

    • Public Static Property Green: Color32 property #

      CSS's green, #008000, half as bright as a screen's green, which is Lime.

    • Public Static Property Lime: Color32 property #

      Lime, green at full strength.

    • Public Static Property Blue: Color32 property #

      Blue.

    • Public Static Property Yellow: Color32 property #

      Yellow.

    • Public Static Property Cyan: Color32 property #

      Cyan.

    • Public Static Property Magenta: Color32 property #

      Magenta.

    • Public Static Property Orange: Color32 property #

      Orange.

    • @PanicsAtCaller Public Static Method Hex(text: String): Color32 static method #

      The color hex text gives, as CSS writes one: "#rgb", "#rgba", "#rrggbb", or "#rrggbbaa", with or without the "#", in either case. Any other text panics; TryHex takes text from outside the program.

    • Public Static Method TryHex(text: String): Color32? static method #

      The color hex text gives, as Hex takes it, or Null for text that isn't one.

    • Public Method ToColor(): Color method #

      The color in linear Floats, through sRGB's gamma.

    • Public Method ToHex(): String method #

      The color as "#rrggbb", lowercase, or "#rrggbbaa" when it isn't opaque.

    • Public Method ToString(): String method #

      Its text, as a string interpolation like "{value}" shows it.

      Doc from std.core.interfaces.Printable.ToString.

    Color struct

    Public Struct Color Implements Hashable, Printable

    Four Floats: linear red, green, and blue, from 0 to 1 for what a screen shows and above for light brighter than white, and alpha, from 0 to 1.

    std/math/color.fb, line 137

    • Public Field r: Float field #

      Its linear red.

    • Public Field g: Float field #

      Its linear green.

    • Public Field b: Float field #

      Its linear blue.

    • Public Field a: Float field #

      Its alpha, from 0, transparent, to 1, opaque.

    • Public Static Property Transparent: Color property #

      No color at all: transparent black.

    • Public Static Property Black: Color property #

      Black.

    • Public Static Property White: Color property #

      White.

    • Public Static Property Gray: Color property #

      sRGB's #808080, half gray as a screen shows it, which is less than half the light.

    • Public Static Property Red: Color property #

      Red.

    • Public Static Property Green: Color property #

      CSS's green, #008000, half as bright as a screen's green, which is Lime.

    • Public Static Property Lime: Color property #

      Lime, green at full strength.

    • Public Static Property Blue: Color property #

      Blue.

    • Public Static Property Yellow: Color property #

      Yellow.

    • Public Static Property Cyan: Color property #

      Cyan.

    • Public Static Property Magenta: Color property #

      Magenta.

    • Public Static Property Orange: Color property #

      sRGB's #ffa500, as CSS's orange.

    • @PanicsAtCaller Public Static Method Hex(text: String): Color static method #

      The color hex text gives, as CSS writes one: "#rgb", "#rgba", "#rrggbb", or "#rrggbbaa", with or without the "#", in either case, in sRGB. Any other text panics; TryHex takes text from outside the program.

    • Public Static Method TryHex(text: String): Color? static method #

      The color hex text gives, as Hex takes it, or Null for text that isn't one.

    • Public Static Method Srgb(r: Float, g: Float, b: Float, a: Float = 1): Color static method #

      The color whose sRGB red, green, and blue, from 0 to 1, these are, as a screen shows them.

    • Public Static Method Hsv(hue: Float, saturation: Float, value: Float, a: Float = 1): Color static method #

      The color of an sRGB hue, saturation, and value, each from 0 to 1, as a color picker gives them: a hue outside 0 to 1 goes around.

    • Public Static Method Hsl(hue: Float, saturation: Float, lightness: Float, a: Float = 1): Color static method #

      The color of an sRGB hue, saturation, and lightness, each from 0 to 1, as CSS's hsl(): a hue outside 0 to 1 goes around.

    • Public Static Method OkLab(lightness: Float, a: Float, b: Float, alpha: Float = 1): Color static method #

      The color of an OKLab lightness and a and b, its green to red and blue to yellow, as Björn Ottosson defined it: a space where equal steps look equal, for blending and ramps.

    • Public Method ToColor32(): Color32 method #

      The color in sRGB bytes, through sRGB's gamma, each kept from 0 to 255 and NaN taken as 0.

    • Public Method ToHex(): String method #

      The color as "#rrggbb", or "#rrggbbaa" when it isn't opaque, in sRGB, as ToColor32 gives it.

    • Public Method ToHsv(): (Float, Float, Float) method #

      The color's sRGB hue, saturation, and value, each from 0 to 1, as Hsv takes them.

    • Public Method ToHsl(): (Float, Float, Float) method #

      The color's sRGB hue, saturation, and lightness, each from 0 to 1, as Hsl takes them.

    • Public Method ToOkLab(): (Float, Float, Float) method #

      The color's OKLab lightness, a, and b, as OkLab takes them.

    • Public Method ToString(): String method #

      Its text, as a string interpolation like "{value}" shows it.

      Doc from std.core.interfaces.Printable.ToString.

    • Operator +(c: Color, d: Color): Color operator #

      c plus d.

    • Operator -(c: Color, d: Color): Color operator #

      c minus d.

    • Operator *(c: Color, d: Color): Color operator #

      Each channel times the other's, as light through a filter.

    • Operator *(c: Color, scale: Float): Color operator #

      c times scale.

    • Operator *(scale: Float, c: Color): Color operator #

      scale times c.

    Functions

    Lerp function

    Public Function Lerp(a: Color, b: Color, t: Float): Color

    The color t of the way from a to b, each channel in linear light, alpha too.

    std/math/color.fb, line 324

    IsClose function

    Public Function IsClose(a: Color, b: Color): Bool

    Whether each channel is close to b's, as IsClose tells for Floats.

    std/math/color.fb, line 329

    Report an issue with this page or with FutureBlitz on GitHub.