struct
Eagle::Color
- Eagle::Color
- Struct
- Value
- Object
Overview
An RGBA color with Float32 components from 0 to 1.
Colors tint everything you draw: Graphics#color, the color: argument on draw
calls, Node2D#modulate, materials and lights. Multiplying a texture by a color
tints it, so Color::WHITE leaves it unchanged.
g.color = Color.hex("#e3a537")
g.circle(100, 100, 20)
g.rect(10, 10, 50, 50, color: Color::RED.with_alpha(0.5)) # translucent
hurt = Color::WHITE.lerp(Color::RED, 0.8) # flash when damaged
rainbow = Color.hsv(Clock.elapsed * 90, 0.8, 1)
shadow = Color::BLACK.alpha(0.3)
Use Color.rgb for 0 to 255 byte values and Color.hex for web-style codes.
Components aren't clamped until they reach the GPU, so values above 1 work for
additive glow.
Defined in:
eagle/math/color.crConstant Summary
-
BLACK =
Color.new(0, 0, 0) -
Opaque black.
-
BLUE =
Color.new(0, 0, 1) -
Pure blue.
-
CORNFLOWER =
Color.rgb(100, 149, 237) -
Cornflower blue, the classic clear color.
-
CYAN =
Color.new(0, 1, 1) -
Pure cyan.
-
GRAY =
Color.new(0.5, 0.5, 0.5) -
50% gray.
-
GREEN =
Color.new(0, 1, 0) -
Pure green.
-
MAGENTA =
Color.new(1, 0, 1) -
Pure magenta.
-
ORANGE =
Color.new(1, 0.5, 0) -
Orange.
-
RED =
Color.new(1, 0, 0) -
Pure red.
-
TRANSPARENT =
Color.new(0, 0, 0, 0) -
Fully transparent. Use it to clear canvases.
-
WHITE =
Color.new(1, 1, 1) -
Opaque white. Draws textures untinted.
-
YELLOW =
Color.new(1, 1, 0) -
Pure yellow.
Constructors
-
.gray(v : Number, a : Number = 1) : Color
A gray of brightness v.
-
.hex(v : Int) : Color
Creates a color from a number:
0xRRGGBB, or0xRRGGBBAAwhen the value is larger than 24 bits. -
.hex(s : String) : Color
Creates a color from a web-style string:
"#rgb","#rgba","#rrggbb"or"#rrggbbaa". -
.hsv(h : Number, s : Number, v : Number, a : Number = 1) : Color
Creates a color from hue in degrees (0 to 360, wraps), plus saturation and value in 0..1.
-
.new(r : Number, g : Number, b : Number, a : Number = 1)
Creates a color from components in 0..1.
-
.new
Creates opaque white.
-
.rgb(r : Int, g : Int, b : Int, a : Int = 255) : Color
Creates a color from 0..255 byte values.
-
.zero : Color
Fully transparent black.
Instance Method Summary
-
#*(o : Color) : Color
Component-wise multiply, which is how tinting works.
-
#*(s : Number) : Color
Scales red, green and blue by s and keeps alpha.
-
#+(o : Color) : Color
Component-wise addition, including alpha.
-
#==(o : Color) : Bool
Exact equality.
-
#a : Float32
Alpha (opacity), from 0 (invisible) to 1 (opaque).
-
#a=(a : Float32)
Alpha (opacity), from 0 (invisible) to 1 (opaque).
-
#alpha(a : Number) : Color
Shorter name for
#with_alpha. -
#b : Float32
Blue, from 0 to 1.
-
#b=(b : Float32)
Blue, from 0 to 1.
-
#darken(t : Number) : Color
Blends toward black by t and keeps alpha.
-
#g : Float32
Green, from 0 to 1.
-
#g=(g : Float32)
Green, from 0 to 1.
-
#lerp(o : Color, t : Number) : Color
Blends toward o by t, including alpha.
-
#lighten(t : Number) : Color
Blends toward white by t and keeps alpha.
-
#premultiplied : Color
Color with red, green and blue multiplied by alpha, for premultiplied blending.
-
#r : Float32
Red, from 0 to 1.
-
#r=(r : Float32)
Red, from 0 to 1.
-
#to_bytes : Tuple(UInt8, UInt8, UInt8, UInt8)
The four channels as bytes, clamped to 0..255.
-
#to_rgba8 : UInt32
Packs the color into
0xRRGGBBAA, clamped to 0..255. -
#to_s(io : IO) : Nil
Same as
#inspect(io). -
#to_vec4 : Vec4
The color as a
Vec4, for shader uniforms. -
#with_alpha(a : Number) : Color
The same color with a different alpha.
Constructor Detail
Creates a color from a number: 0xRRGGBB, or 0xRRGGBBAA when the value is larger than 24 bits.
Creates a color from a web-style string: "#rgb", "#rgba", "#rrggbb" or "#rrggbbaa".
The # is optional.
Creates a color from hue in degrees (0 to 360, wraps), plus saturation and value in 0..1. Sweeping the hue is the easy way to get rainbows.
Creates a color from components in 0..1. Alpha defaults to opaque.
Creates a color from 0..255 byte values.
Color.rgb(255, 136, 0) # orange
Instance Method Detail
Scales red, green and blue by s and keeps alpha. Values above 1 brighten.
Color with red, green and blue multiplied by alpha, for premultiplied blending.