class SFML::Color
32-bit RGBA color, immutable.
SFML::Color.new(255, 100, 50) # opaque SFML::Color.new(255, 100, 50, 128) # half-transparent SFML::Color.rgb(255, 100, 50) # alias SFML::Color.rgba(255, 100, 50, 128) SFML::Color # hex (RGB or RRGGBB or RRGGBBAA) SFML::Color.cornflower_blue # named
Constants
- BLACK
-
Standard
SFMLcolors. - BLUE
-
Pure blue, opaque.
- CORNFLOWER_BLUE
-
A nicer default than pure black for empty windows.
- CYAN
-
Pure cyan, opaque.
- GREEN
-
Pure green, opaque.
- MAGENTA
-
Pure magenta, opaque.
- RED
-
Pure red, opaque.
- TRANSPARENT
-
Fully transparent (alpha = 0).
- WHITE
-
Pure white, opaque.
- YELLOW
-
Pure yellow, opaque.
Attributes
The Red channel (0–255), Green channel (0–255), Blue channel (0–255), Alpha channel (0–255) components.
The Red channel (0–255), Green channel (0–255), Blue channel (0–255), Alpha channel (0–255) components.
The Red channel (0–255), Green channel (0–255), Blue channel (0–255), Alpha channel (0–255) components.
The Red channel (0–255), Green channel (0–255), Blue channel (0–255), Alpha channel (0–255) components.
Public Class Methods
Source
# File lib/sfml/graphics/color.rb, line 36 def self.[](hex) str = hex.to_s.delete_prefix("#") case str.length when 3 new(str[0].hex * 17, str[1].hex * 17, str[2].hex * 17, 255) when 6 new(str[0..1].to_i(16), str[2..3].to_i(16), str[4..5].to_i(16), 255) when 8 new(str[0..1].to_i(16), str[2..3].to_i(16), str[4..5].to_i(16), str[6..7].to_i(16)) else raise ArgumentError, "Color hex must be #RGB, #RRGGBB, or #RRGGBBAA, got #{hex.inspect}" end end
Source
# File lib/sfml/graphics/color.rb, line 140 def black = BLACK # Returns the WHITE singleton. def white = WHITE # Returns the RED singleton. def red = RED # Returns the GREEN singleton. def green = GREEN # Returns the BLUE singleton. def blue = BLUE # Returns the YELLOW singleton. def yellow = YELLOW # Returns the MAGENTA singleton. def magenta = MAGENTA # Returns the CYAN singleton. def cyan = CYAN # Returns the TRANSPARENT singleton (alpha = 0). def transparent = TRANSPARENT # Returns the CORNFLOWER_BLUE singleton — handy default for empty windows. def
Returns the BLACK singleton.
Source
# File lib/sfml/graphics/color.rb, line 148 def blue = BLUE # Returns the YELLOW singleton. def yellow = YELLOW # Returns the MAGENTA singleton. def magenta = MAGENTA # Returns the CYAN singleton. def cyan = CYAN # Returns the TRANSPARENT singleton (alpha = 0). def transparent = TRANSPARENT # Returns the CORNFLOWER_BLUE singleton — handy default for empty windows. def cornflower_blue = CORNFLOWER_BLUE
Source
# File lib/sfml/graphics/color.rb, line 158 def cornflower_blue = CORNFLOWER_BLUE end
Source
# File lib/sfml/graphics/color.rb, line 154 def cyan = CYAN # Returns the TRANSPARENT singleton (alpha = 0). def transparent = TRANSPARENT # Returns the CORNFLOWER_BLUE singleton — handy default for empty windows. def cornflower_blue = CORNFLOWER_BLUE end end end
Source
# File lib/sfml/graphics/color.rb, line 84 def self.from_integer(value) from_native(C::Graphics.sfColor_fromInteger(Integer(value))) end
Build from a packed 0xRRGGBBAA integer.
Source
# File lib/sfml/graphics/color.rb, line 146 def green = GREEN # Returns the BLUE singleton. def blue = BLUE # Returns the YELLOW singleton. def yellow = YELLOW # Returns the MAGENTA singleton. def magenta = MAGENTA # Returns the CYAN singleton. def cyan = CYAN # Returns the TRANSPARENT singleton (alpha = 0). def transparent = TRANSPARENT # Returns the CORNFLOWER_BLUE singleton — handy default for empty windows. def cornflower_blue = CORNFLOWER_BLUE
Source
# File lib/sfml/graphics/color.rb, line 152 def magenta = MAGENTA # Returns the CYAN singleton. def cyan = CYAN # Returns the TRANSPARENT singleton (alpha = 0). def transparent = TRANSPARENT # Returns the CORNFLOWER_BLUE singleton — handy default for empty windows. def cornflower_blue = CORNFLOWER_BLUE end end
Source
# File lib/sfml/graphics/color.rb, line 16 def initialize(r, g, b, a = 255) @r = Integer(r) @g = Integer(g) @b = Integer(b) @a = Integer(a) freeze end
Build a Color from individual channel values. Each must be an Integer in [0, 255]; alpha defaults to 255 (opaque).
Source
# File lib/sfml/graphics/color.rb, line 144 def red = RED # Returns the GREEN singleton. def green = GREEN # Returns the BLUE singleton. def blue = BLUE # Returns the YELLOW singleton. def yellow = YELLOW # Returns the MAGENTA singleton. def magenta = MAGENTA # Returns the CYAN singleton. def cyan = CYAN # Returns the TRANSPARENT singleton (alpha = 0). def transparent = TRANSPARENT # Returns the CORNFLOWER_BLUE singleton — handy default for empty windows. def cornflower_blue =
Source
# File lib/sfml/graphics/color.rb, line 25 def self.rgb(r, g, b) = new(r, g, b, 255) # RGBA constructor — alias for `.new(r, g, b, a)`. def self.rgba(r, g, b, a) = new(r, g, b, a) # Parse a hex color string. Accepts `#RGB` (each digit doubled), # `#RRGGBB` (opaque), or `#RRGGBBAA` (with alpha). The leading # `#` is optional. # # SFML::Color["#ff6432"] #=> Color(255, 100, 50, 255) # SFML::Color["#ff643280"] #=> Color(255, 100, 50, 128) # SFML::Color["#abc"] #=> Color(170, 187, 204, 255) def self.[](hex) str = hex.to_s.delete_prefix("#") case str.length when 3 new(str[0].hex * 17, str[1].hex * 17, str[2].hex * 17, 255) when 6 new(str[0..1].to_i(16), str[2..3].to_i(16), str[4..5].to_i(16), 255) when 8 new(str[0..1].to_i(16), str[2..3].to_i(16), str[4..5].to_i(16), str[6..7].to_i(16)) else raise ArgumentError, "Color hex must be #RGB, #RRGGBB, or #RRGGBBAA, got #{hex.inspect}" end end # Value equality — all four channels must match. def ==(other) other.is_a?(Color) && @r == other.r && @g == other.g && @b == other.b && @a == other.a end alias eql? == # Hash key support. def hash = [@r, @g, @b, @a].hash # `[r, g, b, a]`. def to_a = [@r, @g, @b, @a] # `{r:, g:, b:, a:}`. def to_h = { r: @r, g: @g, b: @b, a: @a } # Pattern-match support for `in [r, g, b, a]`. def deconstruct = to_a # Pattern-match support for `in {r:, g:, b:, a:}`. def deconstruct_keys(_keys) = to_h # String representation for debugging. def to_s = "Color(#{@r}, #{@g}, #{@b}, #{@a})" alias inspect to_s # Returns the to native. def to_native # :nodoc: C::Graphics::Color.new.tap do |c| c[:r] = @r; c[:g] = @g; c[:b] = @b; c[:a] = @a end end # Returns the self. def self.from_native(struct) # :nodoc: new(struct[:r], struct[:g], struct[:b], struct[:a]) end # Build from a packed 0xRRGGBBAA integer. def self.from_integer(value) from_native(C::Graphics.sfColor_fromInteger(Integer(value))) end # Pack this color into a single 0xRRGGBBAA integer. def to_integer = C::Graphics.sfColor_toInteger(to_native) # Component-wise channel arithmetic (saturating in CSFML — values # clamp to [0, 255]). def +(other) raise ArgumentError, "Color +: expected SFML::Color" unless other.is_a?(Color) self.class.from_native(C::Graphics.sfColor_add(to_native, other.to_native)) end # Saturating channel-wise subtraction — values clamp at 0. def -(other) raise ArgumentError, "Color -: expected SFML::Color" unless other.is_a?(Color) self.class.from_native(C::Graphics.sfColor_subtract(to_native, other.to_native)) end # Channel-wise multiply, e.g. for tinting (white modulates to # input; black modulates to black). Uses CSFML's normalised # formula `(a * b) / 255`. def *(other) raise ArgumentError, "Color *: expected SFML::Color" unless other.is_a?(Color) self.class.from_native(C::Graphics.sfColor_modulate(to_native, other.to_native)) end alias modulate * # Standard SFML colors. BLACK = new(0, 0, 0) # Pure white, opaque. WHITE = new(255, 255, 255) # Pure red, opaque. RED = new(255, 0, 0) # Pure green, opaque. GREEN = new(0, 255, 0) # Pure blue, opaque. BLUE = new(0, 0, 255) # Pure yellow, opaque. YELLOW = new(255, 255, 0) # Pure magenta, opaque. MAGENTA = new(255, 0, 255) # Pure cyan, opaque. CYAN = new(0, 255, 255) # Fully transparent (alpha = 0). TRANSPARENT = new(0, 0, 0, 0) # A nicer default than pure black for empty windows. CORNFLOWER_BLUE = new(100, 149, 237) # Convenience accessors for the standard named colors, also # available as `Color::BLACK` etc. for use in constants. class << self # Returns the BLACK singleton. def black = BLACK # Returns the WHITE singleton. def white = WHITE # Returns the RED singleton. def red = RED # Returns the GREEN singleton. def green = GREEN # Returns the BLUE singleton. def blue = BLUE # Returns the YELLOW singleton. def yellow = YELLOW # Returns the MAGENTA singleton. def magenta = MAGENTA # Returns the CYAN singleton. def cyan
Opaque RGB constructor — alias for .new(r, g, b).
Source
# File lib/sfml/graphics/color.rb, line 27 def self.rgba(r, g, b, a) = new(r, g, b, a) # Parse a hex color string. Accepts `#RGB` (each digit doubled), # `#RRGGBB` (opaque), or `#RRGGBBAA` (with alpha). The leading # `#` is optional. # # SFML::Color["#ff6432"] #=> Color(255, 100, 50, 255) # SFML::Color["#ff643280"] #=> Color(255, 100, 50, 128) # SFML::Color["#abc"] #=> Color(170, 187, 204, 255) def self.[](hex) str = hex.to_s.delete_prefix("#") case str.length when 3 new(str[0].hex * 17, str[1].hex * 17, str[2].hex * 17, 255) when 6 new(str[0..1].to_i(16), str[2..3].to_i(16), str[4..5].to_i(16), 255) when 8 new(str[0..1].to_i(16), str[2..3].to_i(16), str[4..5].to_i(16), str[6..7].to_i(16)) else raise ArgumentError, "Color hex must be #RGB, #RRGGBB, or #RRGGBBAA, got #{hex.inspect}" end end # Value equality — all four channels must match. def ==(other) other.is_a?(Color) && @r == other.r && @g == other.g && @b == other.b && @a == other.a end alias eql? == # Hash key support. def hash = [@r, @g, @b, @a].hash # `[r, g, b, a]`. def to_a = [@r, @g, @b, @a] # `{r:, g:, b:, a:}`. def to_h = { r: @r, g: @g, b: @b, a: @a } # Pattern-match support for `in [r, g, b, a]`. def deconstruct = to_a # Pattern-match support for `in {r:, g:, b:, a:}`. def deconstruct_keys(_keys) = to_h # String representation for debugging. def to_s = "Color(#{@r}, #{@g}, #{@b}, #{@a})" alias inspect to_s # Returns the to native. def to_native # :nodoc: C::Graphics::Color.new.tap do |c| c[:r] = @r; c[:g] = @g; c[:b] = @b; c[:a] = @a end end # Returns the self. def self.from_native(struct) # :nodoc: new(struct[:r], struct[:g], struct[:b], struct[:a]) end # Build from a packed 0xRRGGBBAA integer. def self.from_integer(value) from_native(C::Graphics.sfColor_fromInteger(Integer(value))) end # Pack this color into a single 0xRRGGBBAA integer. def to_integer = C::Graphics.sfColor_toInteger(to_native) # Component-wise channel arithmetic (saturating in CSFML — values # clamp to [0, 255]). def +(other) raise ArgumentError, "Color +: expected SFML::Color" unless other.is_a?(Color) self.class.from_native(C::Graphics.sfColor_add(to_native, other.to_native)) end # Saturating channel-wise subtraction — values clamp at 0. def -(other) raise ArgumentError, "Color -: expected SFML::Color" unless other.is_a?(Color) self.class.from_native(C::Graphics.sfColor_subtract(to_native, other.to_native)) end # Channel-wise multiply, e.g. for tinting (white modulates to # input; black modulates to black). Uses CSFML's normalised # formula `(a * b) / 255`. def *(other) raise ArgumentError, "Color *: expected SFML::Color" unless other.is_a?(Color) self.class.from_native(C::Graphics.sfColor_modulate(to_native, other.to_native)) end alias modulate * # Standard SFML colors. BLACK = new(0, 0, 0) # Pure white, opaque. WHITE = new(255, 255, 255) # Pure red, opaque. RED = new(255, 0, 0) # Pure green, opaque. GREEN = new(0, 255, 0) # Pure blue, opaque. BLUE = new(0, 0, 255) # Pure yellow, opaque. YELLOW = new(255, 255, 0) # Pure magenta, opaque. MAGENTA = new(255, 0, 255) # Pure cyan, opaque. CYAN = new(0, 255, 255) # Fully transparent (alpha = 0). TRANSPARENT = new(0, 0, 0, 0) # A nicer default than pure black for empty windows. CORNFLOWER_BLUE = new(100, 149, 237) # Convenience accessors for the standard named colors, also # available as `Color::BLACK` etc. for use in constants. class << self # Returns the BLACK singleton. def black = BLACK # Returns the WHITE singleton. def white = WHITE # Returns the RED singleton. def red = RED # Returns the GREEN singleton. def green = GREEN # Returns the BLUE singleton. def blue = BLUE # Returns the YELLOW singleton. def yellow = YELLOW # Returns the MAGENTA singleton. def magenta = MAGENTA # Returns the CYAN singleton. def cyan =
RGBA constructor — alias for .new(r, g, b, a).
Source
# File lib/sfml/graphics/color.rb, line 156 def transparent = TRANSPARENT # Returns the CORNFLOWER_BLUE singleton — handy default for empty windows. def cornflower_blue = CORNFLOWER_BLUE end end
Source
# File lib/sfml/graphics/color.rb, line 142 def white = WHITE # Returns the RED singleton. def red = RED # Returns the GREEN singleton. def green = GREEN # Returns the BLUE singleton. def blue = BLUE # Returns the YELLOW singleton. def yellow = YELLOW # Returns the MAGENTA singleton. def magenta = MAGENTA # Returns the CYAN singleton. def cyan = CYAN # Returns the TRANSPARENT singleton (alpha = 0). def transparent = TRANSPARENT # Returns the CORNFLOWER_BLUE singleton — handy default for empty windows. def cornflower_blue
Source
# File lib/sfml/graphics/color.rb, line 150 def yellow = YELLOW # Returns the MAGENTA singleton. def magenta = MAGENTA # Returns the CYAN singleton. def cyan = CYAN # Returns the TRANSPARENT singleton (alpha = 0). def transparent = TRANSPARENT # Returns the CORNFLOWER_BLUE singleton — handy default for empty windows. def cornflower_blue = CORNFLOWER_BLUE end
Public Instance Methods
Source
# File lib/sfml/graphics/color.rb, line 108 def *(other) raise ArgumentError, "Color *: expected SFML::Color" unless other.is_a?(Color) self.class.from_native(C::Graphics.sfColor_modulate(to_native, other.to_native)) end
Channel-wise multiply, e.g. for tinting (white modulates to input; black modulates to black). Uses CSFML’s normalised formula (a * b) / 255.
Source
# File lib/sfml/graphics/color.rb, line 94 def +(other) raise ArgumentError, "Color +: expected SFML::Color" unless other.is_a?(Color) self.class.from_native(C::Graphics.sfColor_add(to_native, other.to_native)) end
Component-wise channel arithmetic (saturating in CSFML — values clamp to [0, 255]).
Source
# File lib/sfml/graphics/color.rb, line 100 def -(other) raise ArgumentError, "Color -: expected SFML::Color" unless other.is_a?(Color) self.class.from_native(C::Graphics.sfColor_subtract(to_native, other.to_native)) end
Saturating channel-wise subtraction — values clamp at 0.
Source
# File lib/sfml/graphics/color.rb, line 51 def ==(other) other.is_a?(Color) && @r == other.r && @g == other.g && @b == other.b && @a == other.a end
Value equality — all four channels must match.
Source
# File lib/sfml/graphics/color.rb, line 63 def deconstruct = to_a # Pattern-match support for `in {r:, g:, b:, a:}`. def deconstruct_keys(_keys) = to_h # String representation for debugging. def to_s = "Color(#{@r}, #{@g}, #{@b}, #{@a})" alias inspect to_s # Returns the to native. def to_native # :nodoc: C::Graphics::Color.new.tap do |c| c[:r] = @r; c[:g] = @g; c[:b] = @b; c[:a] = @a end end # Returns the self. def self.from_native(struct) # :nodoc: new(struct[:r], struct[:g], struct[:b], struct[:a]) end # Build from a packed 0xRRGGBBAA integer. def self.from_integer(value) from_native(C::Graphics.sfColor_fromInteger(Integer(value))) end # Pack this color into a single 0xRRGGBBAA integer. def to_integer = C::Graphics.sfColor_toInteger(to_native) # Component-wise channel arithmetic (saturating in CSFML — values # clamp to [0, 255]). def +(other) raise ArgumentError, "Color +: expected SFML::Color" unless other.is_a?(Color) self.class.from_native(C::Graphics.sfColor_add(to_native, other.to_native)) end # Saturating channel-wise subtraction — values clamp at 0. def -(other) raise ArgumentError, "Color -: expected SFML::Color" unless other.is_a?(Color) self.class.from_native(C::Graphics.sfColor_subtract(to_native, other.to_native)) end # Channel-wise multiply, e.g. for tinting (white modulates to # input; black modulates to black). Uses CSFML's normalised # formula `(a * b) / 255`. def *(other) raise ArgumentError, "Color *: expected SFML::Color" unless other.is_a?(Color) self.class.from_native(C::Graphics.sfColor_modulate(to_native, other.to_native)) end alias modulate * # Standard SFML colors. BLACK = new(0, 0, 0) # Pure white, opaque. WHITE = new(255, 255, 255) # Pure red, opaque. RED = new(255, 0, 0) # Pure green, opaque. GREEN = new(0, 255, 0) # Pure blue, opaque. BLUE = new(0, 0, 255) # Pure yellow, opaque. YELLOW = new(255, 255, 0) # Pure magenta, opaque. MAGENTA = new(255, 0, 255) # Pure cyan, opaque. CYAN = new(0, 255, 255) # Fully transparent (alpha = 0). TRANSPARENT = new(0, 0, 0, 0) # A nicer default than pure black for empty windows. CORNFLOWER_BLUE = new(100, 149, 237) # Convenience accessors for the standard named colors, also # available as `Color::BLACK` etc. for use in constants. class << self # Returns the BLACK singleton. def black = BLACK # Returns the WHITE singleton. def white = WHITE # Returns the RED singleton. def red = RED # Returns the GREEN singleton. def green = GREEN # Returns the BLUE singleton. def blue = BLUE # Returns the YELLOW singleton. def yellow = YELLOW # Returns the MAGENTA singleton. def magenta = MAGENTA # Returns the CYAN singleton. def cyan = CYAN # Returns the TRANSPARENT singleton (alpha = 0). def transparent
Pattern-match support for in [r, g, b, a].
Source
# File lib/sfml/graphics/color.rb, line 65 def deconstruct_keys(_keys) = to_h # String representation for debugging. def to_s = "Color(#{@r}, #{@g}, #{@b}, #{@a})" alias inspect to_s # Returns the to native. def to_native # :nodoc: C::Graphics::Color.new.tap do |c| c[:r] = @r; c[:g] = @g; c[:b] = @b; c[:a] = @a end end # Returns the self. def self.from_native(struct) # :nodoc: new(struct[:r], struct[:g], struct[:b], struct[:a]) end # Build from a packed 0xRRGGBBAA integer. def self.from_integer(value) from_native(C::Graphics.sfColor_fromInteger(Integer(value))) end # Pack this color into a single 0xRRGGBBAA integer. def to_integer = C::Graphics.sfColor_toInteger(to_native) # Component-wise channel arithmetic (saturating in CSFML — values # clamp to [0, 255]). def +(other) raise ArgumentError, "Color +: expected SFML::Color" unless other.is_a?(Color) self.class.from_native(C::Graphics.sfColor_add(to_native, other.to_native)) end # Saturating channel-wise subtraction — values clamp at 0. def -(other) raise ArgumentError, "Color -: expected SFML::Color" unless other.is_a?(Color) self.class.from_native(C::Graphics.sfColor_subtract(to_native, other.to_native)) end # Channel-wise multiply, e.g. for tinting (white modulates to # input; black modulates to black). Uses CSFML's normalised # formula `(a * b) / 255`. def *(other) raise ArgumentError, "Color *: expected SFML::Color" unless other.is_a?(Color) self.class.from_native(C::Graphics.sfColor_modulate(to_native, other.to_native)) end alias modulate * # Standard SFML colors. BLACK = new(0, 0, 0) # Pure white, opaque. WHITE = new(255, 255, 255) # Pure red, opaque. RED = new(255, 0, 0) # Pure green, opaque. GREEN = new(0, 255, 0) # Pure blue, opaque. BLUE = new(0, 0, 255) # Pure yellow, opaque. YELLOW = new(255, 255, 0) # Pure magenta, opaque. MAGENTA = new(255, 0, 255) # Pure cyan, opaque. CYAN = new(0, 255, 255) # Fully transparent (alpha = 0). TRANSPARENT = new(0, 0, 0, 0) # A nicer default than pure black for empty windows. CORNFLOWER_BLUE = new(100, 149, 237) # Convenience accessors for the standard named colors, also # available as `Color::BLACK` etc. for use in constants. class << self # Returns the BLACK singleton. def black = BLACK # Returns the WHITE singleton. def white = WHITE # Returns the RED singleton. def red = RED # Returns the GREEN singleton. def green = GREEN # Returns the BLUE singleton. def blue = BLUE # Returns the YELLOW singleton. def yellow = YELLOW # Returns the MAGENTA singleton. def magenta = MAGENTA # Returns the CYAN singleton. def cyan = CYAN # Returns the TRANSPARENT singleton (alpha = 0). def transparent =
Source
# File lib/sfml/graphics/color.rb, line 56 def hash = [@r, @g, @b, @a].hash # `[r, g, b, a]`. def to_a = [@r, @g, @b, @a] # `{r:, g:, b:, a:}`. def to_h = { r: @r, g: @g, b: @b, a: @a } # Pattern-match support for `in [r, g, b, a]`. def deconstruct = to_a # Pattern-match support for `in {r:, g:, b:, a:}`. def deconstruct_keys(_keys) = to_h # String representation for debugging. def to_s = "Color(#{@r}, #{@g}, #{@b}, #{@a})" alias inspect to_s # Returns the to native. def to_native # :nodoc: C::Graphics::Color.new.tap do |c| c[:r] = @r; c[:g] = @g; c[:b] = @b; c[:a] = @a end end # Returns the self. def self.from_native(struct) # :nodoc: new(struct[:r], struct[:g], struct[:b], struct[:a]) end # Build from a packed 0xRRGGBBAA integer. def self.from_integer(value) from_native(C::Graphics.sfColor_fromInteger(Integer(value))) end # Pack this color into a single 0xRRGGBBAA integer. def to_integer = C::Graphics.sfColor_toInteger(to_native) # Component-wise channel arithmetic (saturating in CSFML — values # clamp to [0, 255]). def +(other) raise ArgumentError, "Color +: expected SFML::Color" unless other.is_a?(Color) self.class.from_native(C::Graphics.sfColor_add(to_native, other.to_native)) end # Saturating channel-wise subtraction — values clamp at 0. def -(other) raise ArgumentError, "Color -: expected SFML::Color" unless other.is_a?(Color) self.class.from_native(C::Graphics.sfColor_subtract(to_native, other.to_native)) end # Channel-wise multiply, e.g. for tinting (white modulates to # input; black modulates to black). Uses CSFML's normalised # formula `(a * b) / 255`. def *(other) raise ArgumentError, "Color *: expected SFML::Color" unless other.is_a?(Color) self.class.from_native(C::Graphics.sfColor_modulate(to_native, other.to_native)) end alias modulate * # Standard SFML colors. BLACK = new(0, 0, 0) # Pure white, opaque. WHITE = new(255, 255, 255) # Pure red, opaque. RED = new(255, 0, 0) # Pure green, opaque. GREEN = new(0, 255, 0) # Pure blue, opaque. BLUE = new(0, 0, 255) # Pure yellow, opaque. YELLOW = new(255, 255, 0) # Pure magenta, opaque. MAGENTA = new(255, 0, 255) # Pure cyan, opaque. CYAN = new(0, 255, 255) # Fully transparent (alpha = 0). TRANSPARENT = new(0, 0, 0, 0) # A nicer default than pure black for empty windows. CORNFLOWER_BLUE = new(100, 149, 237) # Convenience accessors for the standard named colors, also # available as `Color::BLACK` etc. for use in constants. class << self # Returns the BLACK singleton. def black = BLACK # Returns the WHITE singleton. def white = WHITE # Returns the RED singleton. def red = RED # Returns the GREEN singleton. def green = GREEN # Returns the BLUE singleton. def blue = BLUE # Returns the YELLOW singleton. def yellow = YELLOW # Returns the MAGENTA singleton. def magenta = MAGENTA # Returns the CYAN singleton. def cyan = CYAN
Hash key support.
Source
# File lib/sfml/graphics/color.rb, line 59 def to_a = [@r, @g, @b, @a] # `{r:, g:, b:, a:}`. def to_h = { r: @r, g: @g, b: @b, a: @a } # Pattern-match support for `in [r, g, b, a]`. def deconstruct = to_a # Pattern-match support for `in {r:, g:, b:, a:}`. def deconstruct_keys(_keys) = to_h # String representation for debugging. def to_s = "Color(#{@r}, #{@g}, #{@b}, #{@a})" alias inspect to_s # Returns the to native. def to_native # :nodoc: C::Graphics::Color.new.tap do |c| c[:r] = @r; c[:g] = @g; c[:b] = @b; c[:a] = @a end end # Returns the self. def self.from_native(struct) # :nodoc: new(struct[:r], struct[:g], struct[:b], struct[:a]) end # Build from a packed 0xRRGGBBAA integer. def self.from_integer(value) from_native(C::Graphics.sfColor_fromInteger(Integer(value))) end # Pack this color into a single 0xRRGGBBAA integer. def to_integer = C::Graphics.sfColor_toInteger(to_native) # Component-wise channel arithmetic (saturating in CSFML — values # clamp to [0, 255]). def +(other) raise ArgumentError, "Color +: expected SFML::Color" unless other.is_a?(Color) self.class.from_native(C::Graphics.sfColor_add(to_native, other.to_native)) end # Saturating channel-wise subtraction — values clamp at 0. def -(other) raise ArgumentError, "Color -: expected SFML::Color" unless other.is_a?(Color) self.class.from_native(C::Graphics.sfColor_subtract(to_native, other.to_native)) end # Channel-wise multiply, e.g. for tinting (white modulates to # input; black modulates to black). Uses CSFML's normalised # formula `(a * b) / 255`. def *(other) raise ArgumentError, "Color *: expected SFML::Color" unless other.is_a?(Color) self.class.from_native(C::Graphics.sfColor_modulate(to_native, other.to_native)) end alias modulate * # Standard SFML colors. BLACK = new(0, 0, 0) # Pure white, opaque. WHITE = new(255, 255, 255) # Pure red, opaque. RED = new(255, 0, 0) # Pure green, opaque. GREEN = new(0, 255, 0) # Pure blue, opaque. BLUE = new(0, 0, 255) # Pure yellow, opaque. YELLOW = new(255, 255, 0) # Pure magenta, opaque. MAGENTA = new(255, 0, 255) # Pure cyan, opaque. CYAN = new(0, 255, 255) # Fully transparent (alpha = 0). TRANSPARENT = new(0, 0, 0, 0) # A nicer default than pure black for empty windows. CORNFLOWER_BLUE = new(100, 149, 237) # Convenience accessors for the standard named colors, also # available as `Color::BLACK` etc. for use in constants. class << self # Returns the BLACK singleton. def black = BLACK # Returns the WHITE singleton. def white = WHITE # Returns the RED singleton. def red = RED # Returns the GREEN singleton. def green = GREEN # Returns the BLUE singleton. def blue = BLUE # Returns the YELLOW singleton. def yellow = YELLOW # Returns the MAGENTA singleton. def magenta = MAGENTA # Returns the CYAN singleton. def cyan = CYAN # Returns the TRANSPARENT singleton (alpha = 0).
[r, g, b, a].
Source
# File lib/sfml/graphics/color.rb, line 61 def to_h = { r: @r, g: @g, b: @b, a: @a } # Pattern-match support for `in [r, g, b, a]`. def deconstruct = to_a # Pattern-match support for `in {r:, g:, b:, a:}`. def deconstruct_keys(_keys) = to_h # String representation for debugging. def to_s = "Color(#{@r}, #{@g}, #{@b}, #{@a})" alias inspect to_s # Returns the to native. def to_native # :nodoc: C::Graphics::Color.new.tap do |c| c[:r] = @r; c[:g] = @g; c[:b] = @b; c[:a] = @a end end # Returns the self. def self.from_native(struct) # :nodoc: new(struct[:r], struct[:g], struct[:b], struct[:a]) end # Build from a packed 0xRRGGBBAA integer. def self.from_integer(value) from_native(C::Graphics.sfColor_fromInteger(Integer(value))) end # Pack this color into a single 0xRRGGBBAA integer. def to_integer = C::Graphics.sfColor_toInteger(to_native) # Component-wise channel arithmetic (saturating in CSFML — values # clamp to [0, 255]). def +(other) raise ArgumentError, "Color +: expected SFML::Color" unless other.is_a?(Color) self.class.from_native(C::Graphics.sfColor_add(to_native, other.to_native)) end # Saturating channel-wise subtraction — values clamp at 0. def -(other) raise ArgumentError, "Color -: expected SFML::Color" unless other.is_a?(Color) self.class.from_native(C::Graphics.sfColor_subtract(to_native, other.to_native)) end # Channel-wise multiply, e.g. for tinting (white modulates to # input; black modulates to black). Uses CSFML's normalised # formula `(a * b) / 255`. def *(other) raise ArgumentError, "Color *: expected SFML::Color" unless other.is_a?(Color) self.class.from_native(C::Graphics.sfColor_modulate(to_native, other.to_native)) end alias modulate * # Standard SFML colors. BLACK = new(0, 0, 0) # Pure white, opaque. WHITE = new(255, 255, 255) # Pure red, opaque. RED = new(255, 0, 0) # Pure green, opaque. GREEN = new(0, 255, 0) # Pure blue, opaque. BLUE = new(0, 0, 255) # Pure yellow, opaque. YELLOW = new(255, 255, 0) # Pure magenta, opaque. MAGENTA = new(255, 0, 255) # Pure cyan, opaque. CYAN = new(0, 255, 255) # Fully transparent (alpha = 0). TRANSPARENT = new(0, 0, 0, 0) # A nicer default than pure black for empty windows. CORNFLOWER_BLUE = new(100, 149, 237) # Convenience accessors for the standard named colors, also # available as `Color::BLACK` etc. for use in constants. class << self # Returns the BLACK singleton. def black = BLACK # Returns the WHITE singleton. def white = WHITE # Returns the RED singleton. def red = RED # Returns the GREEN singleton. def green = GREEN # Returns the BLUE singleton. def blue = BLUE # Returns the YELLOW singleton. def yellow = YELLOW # Returns the MAGENTA singleton. def magenta = MAGENTA # Returns the CYAN singleton. def cyan = CYAN # Returns the TRANSPARENT singleton (alpha = 0). def
Source
# File lib/sfml/graphics/color.rb, line 89 def to_integer = C::Graphics.sfColor_toInteger(to_native) # Component-wise channel arithmetic (saturating in CSFML — values # clamp to [0, 255]). def +(other) raise ArgumentError, "Color +: expected SFML::Color" unless other.is_a?(Color) self.class.from_native(C::Graphics.sfColor_add(to_native, other.to_native)) end # Saturating channel-wise subtraction — values clamp at 0. def -(other) raise ArgumentError, "Color -: expected SFML::Color" unless other.is_a?(Color) self.class.from_native(C::Graphics.sfColor_subtract(to_native, other.to_native)) end # Channel-wise multiply, e.g. for tinting (white modulates to # input; black modulates to black). Uses CSFML's normalised # formula `(a * b) / 255`. def *(other) raise ArgumentError, "Color *: expected SFML::Color" unless other.is_a?(Color) self.class.from_native(C::Graphics.sfColor_modulate(to_native, other.to_native)) end alias modulate * # Standard SFML colors. BLACK = new(0, 0, 0) # Pure white, opaque. WHITE = new(255, 255, 255) # Pure red, opaque. RED = new(255, 0, 0) # Pure green, opaque. GREEN = new(0, 255, 0) # Pure blue, opaque. BLUE = new(0, 0, 255) # Pure yellow, opaque. YELLOW = new(255, 255, 0) # Pure magenta, opaque. MAGENTA = new(255, 0, 255) # Pure cyan, opaque. CYAN = new(0, 255, 255) # Fully transparent (alpha = 0). TRANSPARENT = new(0, 0, 0, 0) # A nicer default than pure black for empty windows. CORNFLOWER_BLUE = new(100, 149, 237) # Convenience accessors for the standard named colors, also # available as `Color::BLACK` etc. for use in constants. class << self # Returns the BLACK singleton. def black = BLACK # Returns the WHITE singleton. def white = WHITE # Returns the RED singleton. def red = RED # Returns the GREEN singleton. def green = GREEN # Returns the BLUE singleton. def blue = BLUE # Returns the YELLOW singleton. def yellow = YELLOW # Returns the MAGENTA singleton. def magenta = MAGENTA # Returns the CYAN singleton. def cyan = CYAN # Returns the TRANSPARENT singleton (alpha = 0). def transparent = TRANSPARENT
Pack this color into a single 0xRRGGBBAA integer.
Source
# File lib/sfml/graphics/color.rb, line 68 def to_s = "Color(#{@r}, #{@g}, #{@b}, #{@a})" alias inspect to_s # Returns the to native. def to_native # :nodoc: C::Graphics::Color.new.tap do |c| c[:r] = @r; c[:g] = @g; c[:b] = @b; c[:a] = @a end end # Returns the self. def self.from_native(struct) # :nodoc: new(struct[:r], struct[:g], struct[:b], struct[:a]) end # Build from a packed 0xRRGGBBAA integer. def self.from_integer(value) from_native(C::Graphics.sfColor_fromInteger(Integer(value))) end # Pack this color into a single 0xRRGGBBAA integer. def to_integer = C::Graphics.sfColor_toInteger(to_native) # Component-wise channel arithmetic (saturating in CSFML — values # clamp to [0, 255]). def +(other) raise ArgumentError, "Color +: expected SFML::Color" unless other.is_a?(Color) self.class.from_native(C::Graphics.sfColor_add(to_native, other.to_native)) end # Saturating channel-wise subtraction — values clamp at 0. def -(other) raise ArgumentError, "Color -: expected SFML::Color" unless other.is_a?(Color) self.class.from_native(C::Graphics.sfColor_subtract(to_native, other.to_native)) end # Channel-wise multiply, e.g. for tinting (white modulates to # input; black modulates to black). Uses CSFML's normalised # formula `(a * b) / 255`. def *(other) raise ArgumentError, "Color *: expected SFML::Color" unless other.is_a?(Color) self.class.from_native(C::Graphics.sfColor_modulate(to_native, other.to_native)) end alias modulate * # Standard SFML colors. BLACK = new(0, 0, 0) # Pure white, opaque. WHITE = new(255, 255, 255) # Pure red, opaque. RED = new(255, 0, 0) # Pure green, opaque. GREEN = new(0, 255, 0) # Pure blue, opaque. BLUE = new(0, 0, 255) # Pure yellow, opaque. YELLOW = new(255, 255, 0) # Pure magenta, opaque. MAGENTA = new(255, 0, 255) # Pure cyan, opaque. CYAN = new(0, 255, 255) # Fully transparent (alpha = 0). TRANSPARENT = new(0, 0, 0, 0) # A nicer default than pure black for empty windows. CORNFLOWER_BLUE = new(100, 149, 237) # Convenience accessors for the standard named colors, also # available as `Color::BLACK` etc. for use in constants. class << self # Returns the BLACK singleton. def black = BLACK # Returns the WHITE singleton. def white = WHITE # Returns the RED singleton. def red = RED # Returns the GREEN singleton. def green = GREEN # Returns the BLUE singleton. def blue = BLUE # Returns the YELLOW singleton. def yellow = YELLOW # Returns the MAGENTA singleton. def magenta = MAGENTA # Returns the CYAN singleton. def cyan = CYAN # Returns the TRANSPARENT singleton (alpha = 0). def transparent = TRANSPARENT
String representation for debugging.