struct Glint::Color

Overview

A wrapper for Raylib::Color.

It provides access to a number of Raylib's color functions.

Always on the look out for more named color palettes!

Defined in:

glint/color.cr

Constant Summary

BEIGE = Color.new(211, 176, 131, 255)
BLACK = Color.new(0, 0, 0, 255)
BLANK = Color.new(0, 0, 0, 0)
BLUE = Color.new(0, 121, 241, 255)
BROWN = Color.new(127, 106, 79, 255)
C64 = {:black => Color.new(0, 0, 0), :white => Color.new(255, 255, 255), :red => Color.new(136, 0, 0), :cyan => Color.new(170, 255, 238), :violet => Color.new(204, 68, 204), :green => Color.new(0, 204, 85), :blue => Color.new(0, 0, 170), :yellow => Color.new(238, 238, 119), :orange => Color.new(221, 136, 85), :brown => Color.new(102, 68, 0), :light_red => Color.new(255, 119, 119), :grey_1 => Color.new(51, 51, 51), :grey_2 => Color.new(119, 119, 119), :light_green => Color.new(170, 255, 102), :light_blue => Color.new(0, 136, 255), :grey_3 => Color.new(187, 187, 187)}

Palette representing the sixteen colours available on the Commodore 64. Source: https://www.c64-wiki.com/wiki/Color

COLOR_RANGE = 0..MAXIMUM_VALUE
DARKBLUE = Color.new(0, 82, 172, 255)
DARKBROWN = Color.new(76, 63, 47, 255)
DARKGRAY = Color.new(80, 80, 80, 255)
DARKGREEN = Color.new(0, 117, 44, 255)
DARKPURPLE = Color.new(112, 31, 126, 255)
GOLD = Color.new(255, 203, 0, 255)
GRAY = Color.new(130, 130, 130, 255)
GREEN = Color.new(0, 228, 48, 255)
LIGHTGRAY = Color.new(200, 200, 200, 255)
LIME = Color.new(0, 158, 47, 255)
MAGENTA = Color.new(255, 0, 255, 255)
MAROON = Color.new(190, 33, 55, 255)
MAXIMUM_VALUE = 255
ONE_BIT = {:black => Color::BLACK, :white => Color::WHITE}

Palette representing the two colours available in a one-bit palette.

ORANGE = Color.new(255, 161, 0, 255)
PINK = Color.new(255, 109, 194, 255)
PURPLE = Color.new(200, 122, 255, 255)
RAYLIB_COLORS = [LIGHTGRAY, GRAY, DARKGRAY, YELLOW, GOLD, ORANGE, PINK, RED, MAROON, GREEN, LIME, DARKGREEN, SKYBLUE, BLUE, DARKBLUE, PURPLE, VIOLET, DARKPURPLE, BEIGE, BROWN, DARKBROWN, WHITE, BLACK, MAGENTA, RAYWHITE, BLANK]
RAYWHITE = Color.new(245, 245, 245, 255)
RED = Color.new(230, 41, 55, 255)
SKYBLUE = Color.new(102, 191, 255, 255)
VIOLET = Color.new(135, 60, 190, 255)
WHITE = Color.new(255, 255, 255, 255)
YELLOW = Color.new(253, 249, 0, 255)

Constructors

Class Method Summary

Instance Method Summary

Macro Summary

Constructor Detail

def self.new(r : Number, g : Number, b : Number, a : Number = MAXIMUM_VALUE) #

Creates a color from an RGB(A) tuple.


[View source]
def self.new(c : Raylib::Color) #

Creates a colour from a Raylib::Color.


[View source]
def self.new(hex_color : String) #

Creates a colour from a 6- or 8-byte hex string (e.g. #ffcc00 or FFCC0080).

The string can optionally begin with # (e.g. when using CSS-style colours). If the alpha component is not specified, it assumes FF (255) for the alpha component.


[View source]
def self.new(value : Number) #

Creates a color from a value.

It could actually be any valid Crystal number, but it probably expects an 8-byte hex (0xNNNNNNNN) number.


[View source]
def self.new(values : Tuple(Int32, Int32, Int32) | Tuple(Int32, Int32, Int32, Int32)) #

[View source]

Class Method Detail

def self.grey(value : Number) #

Creates a grey with the specific value.


[View source]
def self.mix(c1 : Color, c2 : Color) #

Mixes a color with another color to make a new color.


[View source]
def self.random(r_range : Range, g_range : Range, b_range : Range, a_range : Range = COLOR_RANGE) #

Creates a random colour with the specified RGB(A) Ranges.


[View source]
def self.random(transparency : Number = MAXIMUM_VALUE) #

Creates a random Color from the predefined named colors.


[View source]
def self.random_raylib #

Picks a random Color from the predefined Raylib colors.


[View source]

Instance Method Detail

def a #

Returns the alpha component.


[View source]
def a=(value : Number) #

Sets the alpha component.

Returns the Raylib::Color so it can be changed with #adjust.


[View source]
def adjust(&) #

Takes a block and adjusts the color in the way(s) defined by the block.

# Example:
# This takes the predefined `BLACK` colour and makes it semitransparent.
transparent_black = Color::BLACK.adjust { |c| c.a = 127 } # => {255, 255, 255, 127}

[View source]
def alpha #

Returns the color's alpha channel only.


[View source]
def b #

Returns the blue component.


[View source]
def b=(value : Number) #

Sets the blue component.

Returns the Raylib::Color so it can be changed with #adjust.


[View source]
def blue #

Returns the color's blue channel only.


[View source]
def g #

Returns the green component.


[View source]
def g=(value : Number) #

Sets the green component.

Returns the Raylib::Color so it can be changed with #adjust.


[View source]
def green #

Returns the color's green channel only.


[View source]
def mix(other : Color) #

Mixes the color with another color to make a new color.


[View source]
def mix!(other : Color) #

Changes the color to a mix with with another color.


[View source]
def r #

Returns the red component.


[View source]
def r=(value : Number) #

Sets the red component.

Returns the Raylib::Color so it can be changed with #adjust.


[View source]
def red #

Returns the color's red channel only.


[View source]
def semitransparent! #

Sets the alpha value to 127.


[View source]
def semitransparent? #

Returns whether the color is semitransparent.


[View source]
def to_hash #

Returns the color's values as a Hash.


[View source]
def to_hex #

[View source]
def to_s(io : IO) #

Returns a string representation of the color.


[View source]
def to_tuple #

Returns the color's values as a Tuple.


[View source]
def to_unsafe : Raylib::Color #

Returns the color in a C-compatible format, i.e. as Raylib::Color.

This allows for transparent interoperability with the Raylib library.


[View source]
def translucent? #

Returns whether the color is semitransparent.


[View source]
def transparent! #

Sets the alpha value to 0.


[View source]
def transparent? #

Returns whether the colour is fully transparent.


[View source]
def values #

Returns the color's values as a Tuple.


[View source]

Macro Detail

macro method_missing(call) #

[View source]