Class: Gauguin::Color
- Inherits:
-
Object
- Object
- Gauguin::Color
- Defined in:
- lib/gauguin/color.rb
Instance Attribute Summary collapse
-
#blue ⇒ Object
Returns the value of attribute blue.
-
#green ⇒ Object
Returns the value of attribute green.
-
#percentage ⇒ Object
Returns the value of attribute percentage.
-
#red ⇒ Object
Returns the value of attribute red.
-
#transparent ⇒ Object
Returns the value of attribute transparent.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #distance(other_color) ⇒ Object
- #hash ⇒ Object
-
#initialize(red, green, blue, percentage = 1, transparent = false) ⇒ Color
constructor
A new instance of Color.
- #inspect ⇒ Object
- #similar?(other_color) ⇒ Boolean
- #to_a ⇒ Object
- #to_key ⇒ Object
- #to_lab ⇒ Object
- #to_rgb ⇒ Object
- #to_s ⇒ Object
- #to_vector ⇒ Object
- #transparent? ⇒ Boolean
Constructor Details
#initialize(red, green, blue, percentage = 1, transparent = false) ⇒ Color
Returns a new instance of Color.
5 6 7 8 9 10 11 |
# File 'lib/gauguin/color.rb', line 5 def initialize(red, green, blue, percentage = 1, transparent = false) self.red = red self.green = green self.blue = blue self.percentage = percentage self.transparent = transparent end |
Instance Attribute Details
#blue ⇒ Object
Returns the value of attribute blue.
3 4 5 |
# File 'lib/gauguin/color.rb', line 3 def blue @blue end |
#green ⇒ Object
Returns the value of attribute green.
3 4 5 |
# File 'lib/gauguin/color.rb', line 3 def green @green end |
#percentage ⇒ Object
Returns the value of attribute percentage.
3 4 5 |
# File 'lib/gauguin/color.rb', line 3 def percentage @percentage end |
#red ⇒ Object
Returns the value of attribute red.
3 4 5 |
# File 'lib/gauguin/color.rb', line 3 def red @red end |
#transparent ⇒ Object
Returns the value of attribute transparent.
3 4 5 |
# File 'lib/gauguin/color.rb', line 3 def transparent @transparent end |
Class Method Details
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
13 14 15 |
# File 'lib/gauguin/color.rb', line 13 def ==(other) self.class == other.class && self.to_key == other.to_key end |
#distance(other_color) ⇒ Object
28 29 30 |
# File 'lib/gauguin/color.rb', line 28 def distance(other_color) (self.to_lab - other_color.to_lab).r end |
#hash ⇒ Object
19 20 21 |
# File 'lib/gauguin/color.rb', line 19 def hash self.to_key.hash end |
#inspect ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/gauguin/color.rb', line 63 def inspect msg = "#{to_s}[#{percentage}]" if transparent? msg += "[transparent]" end msg end |
#similar?(other_color) ⇒ Boolean
23 24 25 26 |
# File 'lib/gauguin/color.rb', line 23 def similar?(other_color) self.transparent == other_color.transparent && self.distance(other_color) < Gauguin.configuration.color_similarity_threshold end |
#to_a ⇒ Object
46 47 48 |
# File 'lib/gauguin/color.rb', line 46 def to_a to_rgb + [self.percentage, self.transparent] end |
#to_key ⇒ Object
55 56 57 |
# File 'lib/gauguin/color.rb', line 55 def to_key to_rgb + [self.transparent] end |
#to_lab ⇒ Object
32 33 34 35 36 |
# File 'lib/gauguin/color.rb', line 32 def to_lab rgb_vector = self.to_vector xyz_vector = rgb_vector.to_xyz xyz_vector.to_lab end |
#to_rgb ⇒ Object
42 43 44 |
# File 'lib/gauguin/color.rb', line 42 def to_rgb [self.red, self.green, self.blue] end |
#to_s ⇒ Object
59 60 61 |
# File 'lib/gauguin/color.rb', line 59 def to_s "rgb(#{self.red}, #{self.green}, #{self.blue})" end |
#to_vector ⇒ Object
38 39 40 |
# File 'lib/gauguin/color.rb', line 38 def to_vector ColorSpace::RgbVector[*to_rgb] end |
#transparent? ⇒ Boolean
71 72 73 |
# File 'lib/gauguin/color.rb', line 71 def transparent? self.transparent end |