Class: RGhost::RGB
Overview
Creates RGB color
Constant Summary collapse
Instance Attribute Summary collapse
-
#blue ⇒ Object
Returns the value of attribute blue.
-
#green ⇒ Object
Returns the value of attribute green.
-
#red ⇒ Object
Returns the value of attribute red.
Instance Method Summary collapse
- #color_params ⇒ Object
-
#initialize(color_or_red = nil, green = nil, blue = nil) ⇒ RGB
constructor
String HTML color converter Color.create ‘#FFAA33’ As Symbol will be find in RGhost::Constants::Colors::RGB Color.create :red As Array with 3 elements Color.create [0.5, 0.3, 0.5] Hash with 3 pair of key/value.
- #ps ⇒ Object
- #stack_format ⇒ Object
Methods inherited from Color
Methods included from RubyToPs
#array_to_stack, #hash_to_array, #pack_string, #ps_escape, #string_eval, #to_array, #to_bool, #to_string, #to_string_array
Methods inherited from PsObject
#<<, #call, #graphic_scope, #raw, #set, #to_s
Constructor Details
#initialize(color_or_red = nil, green = nil, blue = nil) ⇒ RGB
String HTML color converter Color.create ‘#FFAA33’ As Symbol will be find in RGhost::Constants::Colors::RGB Color.create :red
As Array with 3 elements Color.create [0.5, 0.3, 0.5] Hash with 3 pair of key/value. Valids keys :red, :green and :blue Color.create :red => 0.5, :green => 0.3, :blue => 0.5 Hash with 3 pair of key/value. Valids keys :r, :g and :b Color.create :r => 0.5, :g => 0.3, :b => 0.5
79 80 81 82 83 84 |
# File 'lib/rghost/color.rb', line 79 def initialize(color_or_red=nil,green=nil,blue=nil) @color=color_or_red @color=[color_or_red.to_f,green.to_f,blue.to_f] if color_or_red.is_a? Numeric @color=DEFAULT_RGB.merge(color_or_red) if color_or_red.is_a? Hash end |
Instance Attribute Details
#blue ⇒ Object
Returns the value of attribute blue.
66 67 68 |
# File 'lib/rghost/color.rb', line 66 def blue @blue end |
#green ⇒ Object
Returns the value of attribute green.
66 67 68 |
# File 'lib/rghost/color.rb', line 66 def green @green end |
#red ⇒ Object
Returns the value of attribute red.
66 67 68 |
# File 'lib/rghost/color.rb', line 66 def red @red end |
Instance Method Details
#color_params ⇒ Object
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/rghost/color.rb', line 94 def color_params case @color when Hash then [@color[:red] || @color[:r],@color[:green] || @color[:g],@color[:blue] || @color[:b]] when Array then @color when String then hex_to_rgb(@color) when NilClass then [0,0,1] end end |
#ps ⇒ Object
86 87 88 89 90 |
# File 'lib/rghost/color.rb', line 86 def ps value=color_params array_to_stack(value.map{|n| n > 1 ? n/100.0: n})+"setrgbcolor" end |
#stack_format ⇒ Object
91 92 93 |
# File 'lib/rghost/color.rb', line 91 def stack_format color_params end |