class Gosu::Color

Overview

Represents an ARGB color value with 8 bits for each channel. Colors can be used interchangeably with integer literals of the form 0xAARRGGBB in all Gosu APIs.

Defined in:

gosu/color.cr

Constant Summary

AQUA = Gosu::Color.argb(4278255615_i64)
BLACK = Gosu::Color.argb(4278190080_i64)
BLUE = Gosu::Color.argb(4278190335_i64)
CYAN = Gosu::Color.argb(4278255615_i64)
FUCHSIA = Gosu::Color.argb(4294902015_i64)
GRAY = Gosu::Color.argb(4286611584_i64)
GREEN = Gosu::Color.argb(4278255360_i64)
NONE = Gosu::Color.argb(0)
RED = Gosu::Color.argb(4294901760_i64)
WHITE = Gosu::Color.argb(4294967295_i64)
YELLOW = Gosu::Color.argb(4294967040_i64)

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(alpha : UInt8 | Int32, red : UInt8 | Int32, green : UInt8 | Int32, blue : UInt8 | Int32) #

Creates color from four unsigned 8-bit integers.


[View source]
def self.new(color : UInt32) #

Creates color from 0xAARRGGBB integer literal.


[View source]

Class Method Detail

def self.argb(alpha : UInt8 | Int32, red : UInt8 | Int32, green : UInt8 | Int32, blue : UInt8 | Int32) : Gosu::Color #

[View source]
def self.argb(color : UInt32) : Gosu::Color #

Creates color from 0xAARRGGBB integer literal.


[View source]
def self.from_ahsv(alpha : UInt8 | Int32, hue : Float64, saturation : Float64, value : Float64) : Gosu::Color #

Converts an HSV triplet to a color with the alpha channel set to a given value.


[View source]
def self.from_hsv(hue : Float64, saturation : Float64, value : Float64) : Gosu::Color #

Converts an HSV triplet to an opaque color.


[View source]
def self.rgb(red : UInt8 | Int32, green : UInt8 | Int32, blue : UInt8 | Int32) : Gosu::Color #

[View source]
def self.rgba(red : UInt8 | Int32, green : UInt8 | Int32, blue : UInt8 | Int32, alpha : UInt8 | Int32) : Gosu::Color #

[View source]
def self.safe_to_u8(value : Int32 | UInt8) : UInt8 #

Converts Int32 to UInt8 safely, by clamping value to range [0; 255] then converting to UInt8.


[View source]

Instance Method Detail

def ==(other : Gosu::Color) : Bool #

[View source]
def alpha : UInt8 #

Returns the color's alpha channel.


[View source]
def alpha=(value : UInt8 | Int32) : UInt32 #

Set the color's alpha channel.


[View source]
def blue : UInt8 #

Returns the color's blue channel.


[View source]
def blue=(value : UInt8 | Int32) : UInt32 #

Sets the color's green channel.


[View source]
def eql?(other) : Bool #

[View source]
def gl : UInt32 #

Returns a 32-bit representation of the color suitable for use with OpenGL calls. This color is stored in a fixed order in memory and its integer value may vary depending on your system's byte order.


[View source]
def green : UInt8 #

Returns the color's green channel.


[View source]
def green=(value : UInt8 | Int32) : UInt32 #

Sets the color's green channel.


[View source]
def hash #
Description copied from class Object

Generates an UInt64 hash value for this object.

This method must have the property that a == b implies a.hash == b.hash.

The hash value is used along with #== by the Hash class to determine if two objects reference the same hash key.

Subclasses must not override this method. Instead, they must define hash(hasher), though usually the macro def_hash can be used to generate this method.


[View source]
def hue : Float64 #

Returns the color's hue.


[View source]
def hue=(value : Float64 | Int32) : UInt32 #

Sets the color's hue.


[View source]
def red : UInt8 #

Returns the color's red channel.


[View source]
def red=(value : UInt8 | Int32) : UInt32 #

Sets the color's red channel.


[View source]
def saturation : Float64 #

Returns the color's saturation.


[View source]
def saturation=(value : Float64 | Int32) : UInt32 #

Sets the color's saturation.


[View source]
def value : Float64 #

Returns the color's value (lightness).


[View source]
def value=(value : Float64 | Int32) : UInt32 #

Sets the color's value.


[View source]