Class: SFML::Color
- Inherits:
-
Object
- Object
- SFML::Color
- Defined in:
- lib/sfml/graphics/color.rb
Overview
Constant Summary collapse
- BLACK =
Standard SFML colors.
new(0, 0, 0)
- WHITE =
new(255, 255, 255)
- RED =
new(255, 0, 0)
- GREEN =
new(0, 255, 0)
- BLUE =
new(0, 0, 255)
- YELLOW =
new(255, 255, 0)
- MAGENTA =
new(255, 0, 255)
- CYAN =
new(0, 255, 255)
- TRANSPARENT =
new(0, 0, 0, 0)
- CORNFLOWER_BLUE =
A nicer default than pure black for empty windows.
new(100, 149, 237)
Instance Attribute Summary collapse
-
#a ⇒ Object
readonly
Returns the value of attribute a.
-
#b ⇒ Object
readonly
Returns the value of attribute b.
-
#g ⇒ Object
readonly
Returns the value of attribute g.
-
#r ⇒ Object
readonly
Returns the value of attribute r.
Class Method Summary collapse
- .[](hex) ⇒ Object
- .black ⇒ Object
- .blue ⇒ Object
- .cornflower_blue ⇒ Object
- .cyan ⇒ Object
-
.from_native(struct) ⇒ Object
:nodoc:.
- .green ⇒ Object
- .magenta ⇒ Object
- .red ⇒ Object
- .rgb(r, g, b) ⇒ Object
- .rgba(r, g, b, a) ⇒ Object
- .transparent ⇒ Object
- .white ⇒ Object
- .yellow ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #deconstruct ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #hash ⇒ Object
-
#initialize(r, g, b, a = 255) ⇒ Color
constructor
A new instance of Color.
- #to_a ⇒ Object
- #to_h ⇒ Object
-
#to_native ⇒ Object
:nodoc:.
- #to_s ⇒ Object (also: #inspect)
Constructor Details
#initialize(r, g, b, a = 255) ⇒ Color
Returns a new instance of Color.
13 14 15 16 17 18 19 |
# File 'lib/sfml/graphics/color.rb', line 13 def initialize(r, g, b, a = 255) @r = Integer(r) @g = Integer(g) @b = Integer(b) @a = Integer(a) freeze end |
Instance Attribute Details
#a ⇒ Object (readonly)
Returns the value of attribute a.
11 12 13 |
# File 'lib/sfml/graphics/color.rb', line 11 def a @a end |
#b ⇒ Object (readonly)
Returns the value of attribute b.
11 12 13 |
# File 'lib/sfml/graphics/color.rb', line 11 def b @b end |
#g ⇒ Object (readonly)
Returns the value of attribute g.
11 12 13 |
# File 'lib/sfml/graphics/color.rb', line 11 def g @g end |
#r ⇒ Object (readonly)
Returns the value of attribute r.
11 12 13 |
# File 'lib/sfml/graphics/color.rb', line 11 def r @r end |
Class Method Details
.[](hex) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/sfml/graphics/color.rb', line 24 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 |
.black ⇒ Object
77 |
# File 'lib/sfml/graphics/color.rb', line 77 def black = BLACK |
.blue ⇒ Object
81 |
# File 'lib/sfml/graphics/color.rb', line 81 def blue = BLUE |
.cornflower_blue ⇒ Object
86 |
# File 'lib/sfml/graphics/color.rb', line 86 def cornflower_blue = CORNFLOWER_BLUE |
.cyan ⇒ Object
84 |
# File 'lib/sfml/graphics/color.rb', line 84 def cyan = CYAN |
.from_native(struct) ⇒ Object
:nodoc:
58 59 60 |
# File 'lib/sfml/graphics/color.rb', line 58 def self.from_native(struct) # :nodoc: new(struct[:r], struct[:g], struct[:b], struct[:a]) end |
.green ⇒ Object
80 |
# File 'lib/sfml/graphics/color.rb', line 80 def green = GREEN |
.magenta ⇒ Object
83 |
# File 'lib/sfml/graphics/color.rb', line 83 def magenta = MAGENTA |
.red ⇒ Object
79 |
# File 'lib/sfml/graphics/color.rb', line 79 def red = RED |
.rgb(r, g, b) ⇒ Object
21 |
# File 'lib/sfml/graphics/color.rb', line 21 def self.rgb(r, g, b) = new(r, g, b, 255) |
.rgba(r, g, b, a) ⇒ Object
22 |
# File 'lib/sfml/graphics/color.rb', line 22 def self.rgba(r, g, b, a) = new(r, g, b, a) |
.transparent ⇒ Object
85 |
# File 'lib/sfml/graphics/color.rb', line 85 def transparent = TRANSPARENT |
.white ⇒ Object
78 |
# File 'lib/sfml/graphics/color.rb', line 78 def white = WHITE |
.yellow ⇒ Object
82 |
# File 'lib/sfml/graphics/color.rb', line 82 def yellow = YELLOW |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
38 39 40 |
# File 'lib/sfml/graphics/color.rb', line 38 def ==(other) other.is_a?(Color) && @r == other.r && @g == other.g && @b == other.b && @a == other.a end |
#deconstruct ⇒ Object
46 |
# File 'lib/sfml/graphics/color.rb', line 46 def deconstruct = to_a |
#deconstruct_keys(_keys) ⇒ Object
47 |
# File 'lib/sfml/graphics/color.rb', line 47 def deconstruct_keys(_keys) = to_h |
#hash ⇒ Object
42 |
# File 'lib/sfml/graphics/color.rb', line 42 def hash = [@r, @g, @b, @a].hash |
#to_a ⇒ Object
44 |
# File 'lib/sfml/graphics/color.rb', line 44 def to_a = [@r, @g, @b, @a] |
#to_h ⇒ Object
45 |
# File 'lib/sfml/graphics/color.rb', line 45 def to_h = { r: @r, g: @g, b: @b, a: @a } |
#to_native ⇒ Object
:nodoc:
52 53 54 55 56 |
# File 'lib/sfml/graphics/color.rb', line 52 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 |
#to_s ⇒ Object Also known as: inspect
49 |
# File 'lib/sfml/graphics/color.rb', line 49 def to_s = "Color(#{@r}, #{@g}, #{@b}, #{@a})" |