Class Rubygame::Color::ColorRGB
In: lib/rubygame/color/models/rgb.rb
Parent: Object

Represents color in the RGB (Red, Green, Blue) color space.

Methods

Included Modules

ColorBase

Attributes

a  [R] 
b  [R] 
g  [R] 
r  [R] 

Public Class methods

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.

[Source]

# 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

[Source]

# File lib/rubygame/color/models/rgb.rb, line 67
                                def new_from_rgba( rgba )
                                        new( rgba )
                                end

[Source]

# 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

Public Instance methods

inspect()

Alias for to_s

[Source]

# File lib/rubygame/color/models/rgb.rb, line 57
                        def to_rgba_ary
                                return [@r, @g, @b, @a]
                        end

[Source]

# File lib/rubygame/color/models/rgb.rb, line 61
                        def to_s
                                "#<#{self.class} [#{@r}, #{@g}, #{@b}, #{@a}]>"
                        end

Converts the color to an RGBA array of integers ranging from 0 to 255, as SDL wants.

[Source]

# 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

[Validate]