Class: Rubygame::Color::ColorRGB
- Inherits:
-
Object
- Object
- Rubygame::Color::ColorRGB
- Includes:
- ColorBase
- Defined in:
- lib/rubygame/color/models/rgb.rb
Overview
Represents color in the RGB (Red, Green, Blue) color space.
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
Instance Method Summary collapse
-
#initialize(color) ⇒ ColorRGB
constructor
call-seq: new( [r,g,b,a] ) -> ColorRGB new( [r,g,b] ) -> ColorRGB new( color ) -> ColorRGB.
- #to_rgba_ary ⇒ Object
- #to_s ⇒ Object (also: #inspect)
-
#to_sdl_rgba_ary ⇒ Object
Converts the color to an RGBA array of integers ranging from 0 to 255, as SDL wants.
Methods included from ColorBase
#*, #+, #-, #/, #average, #over
Constructor Details
#initialize(color) ⇒ ColorRGB
call-seq:
new( [r,g,b,a] ) -> ColorRGB
new( [r,g,b] ) -> ColorRGB
new( color ) -> ColorRGB
Create a new instance from an Array or an existing color (of any type). If the alpha (opacity) component is omitted from the array, full opacity will be used.
All color components range from 0.0 to 1.0.
42 43 44 45 46 47 48 49 |
# File 'lib/rubygame/color/models/rgb.rb', line 42 def initialize( color ) if color.kind_of?(Array) @r, @g, @b, @a = color.collect { |i| i.to_f } @a = 1.0 unless @a elsif color.respond_to?(:to_rgba_ary) @r, @g, @b, @a = color.to_rgba_ary end end |
Instance Attribute Details
#a ⇒ Object (readonly)
Returns the value of attribute a.
29 30 31 |
# File 'lib/rubygame/color/models/rgb.rb', line 29 def a @a end |
#b ⇒ Object (readonly)
Returns the value of attribute b.
29 30 31 |
# File 'lib/rubygame/color/models/rgb.rb', line 29 def b @b end |
#g ⇒ Object (readonly)
Returns the value of attribute g.
29 30 31 |
# File 'lib/rubygame/color/models/rgb.rb', line 29 def g @g end |
#r ⇒ Object (readonly)
Returns the value of attribute r.
29 30 31 |
# File 'lib/rubygame/color/models/rgb.rb', line 29 def r @r end |
Class Method Details
.new_from_rgba(rgba) ⇒ Object
67 68 69 |
# File 'lib/rubygame/color/models/rgb.rb', line 67 def new_from_rgba( rgba ) new( rgba ) end |
.new_from_sdl_rgba(rgba) ⇒ Object
71 72 73 |
# File 'lib/rubygame/color/models/rgb.rb', line 71 def new_from_sdl_rgba( rgba ) new_from_rgba( rgba.collect { |i| i / 255.0 } ) end |
Instance Method Details
#to_rgba_ary ⇒ Object
57 58 59 |
# File 'lib/rubygame/color/models/rgb.rb', line 57 def to_rgba_ary return [@r, @g, @b, @a] end |
#to_s ⇒ Object Also known as: inspect
61 62 63 |
# File 'lib/rubygame/color/models/rgb.rb', line 61 def to_s "#<#{self.class} [#{@r}, #{@g}, #{@b}, #{@a}]>" end |
#to_sdl_rgba_ary ⇒ Object
Converts the color to an RGBA array of integers ranging from 0 to 255, as SDL wants.
53 54 55 |
# File 'lib/rubygame/color/models/rgb.rb', line 53 def to_sdl_rgba_ary self.to_rgba_ary.collect { |i| (i * 255).to_i } end |