Class: Color
- Inherits:
-
Object
- Object
- Color
- Defined in:
- lib/rgss3/color.rb
Instance Attribute Summary collapse
-
#gosu_color ⇒ Object
Returns the value of attribute gosu_color.
Class Method Summary collapse
- ._load(s) ⇒ Object
- .from_gosu(gosu_color) ⇒ Object
- .from_pixel(pixel) ⇒ Object
- .rgba_from_int(rgba) ⇒ Object
- .rgba_from_pixel(pixel) ⇒ Object
- .try_convert(color) ⇒ Object
Instance Method Summary collapse
- #_dump(d = 0) ⇒ Object
- #alpha ⇒ Object
- #alpha=(value) ⇒ Object
- #alpha_i ⇒ Object
- #blue ⇒ Object
- #blue=(value) ⇒ Object
- #blue_i ⇒ Object
- #empty ⇒ Object
- #from_int(rgba) ⇒ Object
- #green ⇒ Object
- #green=(value) ⇒ Object
- #green_i ⇒ Object
-
#initialize(*args) ⇒ Color
constructor
A new instance of Color.
- #red ⇒ Object
- #red=(value) ⇒ Object
- #red_i ⇒ Object
- #set(*args) ⇒ Object
- #to_a ⇒ Object (also: #rgba)
- #to_fa ⇒ Object
- #to_gosu ⇒ Object
- #to_pixel ⇒ Object
- #to_rmagick_color ⇒ Object
- #to_s ⇒ Object (also: #inspect)
Constructor Details
#initialize(*args) ⇒ Color
Returns a new instance of Color.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/rgss3/color.rb', line 6 def initialize(*args) case args.size when 0 empty when 3, 4 set(*args) else raise ArgumentError end end |
Instance Attribute Details
#gosu_color ⇒ Object
Returns the value of attribute gosu_color.
4 5 6 |
# File 'lib/rgss3/color.rb', line 4 def gosu_color @gosu_color end |
Class Method Details
._load(s) ⇒ Object
118 119 120 |
# File 'lib/rgss3/color.rb', line 118 def self._load(s) new(*s.unpack('d4')) end |
.from_gosu(gosu_color) ⇒ Object
159 160 161 162 163 |
# File 'lib/rgss3/color.rb', line 159 def self.from_gosu(gosu_color) color = allocate color.gosu_color = gosu_color color end |
.from_pixel(pixel) ⇒ Object
137 138 139 |
# File 'lib/rgss3/color.rb', line 137 def self.from_pixel(pixel) new(*rgba_from_pixel(pixel)) end |
.rgba_from_int(rgba) ⇒ Object
152 153 154 155 156 157 |
# File 'lib/rgss3/color.rb', line 152 def self.rgba_from_int(rgba) (0...4).each_with_object(Array.new(4)) do |i, result| result[3 - i] = rgba & 0xff rgba >>= 8 end end |
.rgba_from_pixel(pixel) ⇒ Object
141 142 143 144 145 146 |
# File 'lib/rgss3/color.rb', line 141 def self.rgba_from_pixel(pixel) # "#RRGGBBAA" rgba_hex = pixel.to_color(Magick::AllCompliance, true, 8, true) rgba = rgba_hex[1, 8].to_i(16) rgba_from_int(rgba) end |
.try_convert(color) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/rgss3/color.rb', line 122 def self.try_convert(color) case color when Color color when String from_pixel Magick::Pixel.from_color(color) when Integer from_int(color) when Magick::Pixel from_pixel(color) when Gosu::Color from_gosu(color) end end |
Instance Method Details
#_dump(d = 0) ⇒ Object
114 115 116 |
# File 'lib/rgss3/color.rb', line 114 def _dump(d = 0) [red, green, blue, alpha].pack('d4') end |
#alpha ⇒ Object
46 47 48 |
# File 'lib/rgss3/color.rb', line 46 def alpha @gosu_color.alpha.to_f end |
#alpha=(value) ⇒ Object
82 83 84 |
# File 'lib/rgss3/color.rb', line 82 def alpha=(value) @gosu_color.alpha = value end |
#alpha_i ⇒ Object
62 63 64 |
# File 'lib/rgss3/color.rb', line 62 def alpha_i @gosu_color.alpha end |
#blue ⇒ Object
38 39 40 |
# File 'lib/rgss3/color.rb', line 38 def blue @gosu_color.blue.to_f end |
#blue=(value) ⇒ Object
74 75 76 |
# File 'lib/rgss3/color.rb', line 74 def blue=(value) @gosu_color.blue = value end |
#blue_i ⇒ Object
54 55 56 |
# File 'lib/rgss3/color.rb', line 54 def blue_i @gosu_color.blue end |
#empty ⇒ Object
66 67 68 |
# File 'lib/rgss3/color.rb', line 66 def empty @gosu_color = Gosu::Color::NONE end |
#from_int(rgba) ⇒ Object
148 149 150 |
# File 'lib/rgss3/color.rb', line 148 def from_int(rgba) new(*rgba_from_int(rgba)) end |
#green ⇒ Object
42 43 44 |
# File 'lib/rgss3/color.rb', line 42 def green @gosu_color.green.to_f end |
#green=(value) ⇒ Object
78 79 80 |
# File 'lib/rgss3/color.rb', line 78 def green=(value) @gosu_color.green = value end |
#green_i ⇒ Object
58 59 60 |
# File 'lib/rgss3/color.rb', line 58 def green_i @gosu_color.green end |
#red ⇒ Object
34 35 36 |
# File 'lib/rgss3/color.rb', line 34 def red @gosu_color.red.to_f end |
#red=(value) ⇒ Object
70 71 72 |
# File 'lib/rgss3/color.rb', line 70 def red=(value) @gosu_color.red = value end |
#red_i ⇒ Object
50 51 52 |
# File 'lib/rgss3/color.rb', line 50 def red_i @gosu_color.red end |
#set(*args) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rgss3/color.rb', line 17 def set(*args) case args.size when 1 if args[0].is_a?(Color) @gosu_color = args[0].to_gosu else raise ArgumentError end when 3 @gosu_color = Gosu::Color.rgba(*args.map(&:round), 255) when 4 @gosu_color = Gosu::Color.rgba(*args.map(&:round)) else raise ArgumentError end end |
#to_a ⇒ Object Also known as: rgba
86 87 88 |
# File 'lib/rgss3/color.rb', line 86 def to_a [red_i, green_i, blue_i, alpha_i] end |
#to_fa ⇒ Object
98 99 100 |
# File 'lib/rgss3/color.rb', line 98 def to_fa [red, green, blue, alpha] end |
#to_gosu ⇒ Object
102 103 104 |
# File 'lib/rgss3/color.rb', line 102 def to_gosu @gosu_color.dup end |
#to_pixel ⇒ Object
106 107 108 |
# File 'lib/rgss3/color.rb', line 106 def to_pixel Magick::Pixel.from_color(to_rmagick_color) end |
#to_rmagick_color ⇒ Object
110 111 112 |
# File 'lib/rgss3/color.rb', line 110 def to_rmagick_color "rgba(#{red_i},#{green_i},#{blue_i},#{alpha_i})" end |
#to_s ⇒ Object Also known as: inspect
92 93 94 |
# File 'lib/rgss3/color.rb', line 92 def to_s format '(%.6f, %.6f, %.6f, %.6f)', red, green, blue, alpha end |