class Gauguin::Color

Attributes

blue[RW]
green[RW]
percentage[RW]
red[RW]
transparent[RW]

Public Class Methods

from_a(array) click to toggle source
# File lib/gauguin/color.rb, line 50
def self.from_a(array)
  red, green, blue, percentage, transparent = array
  Color.new(red, green, blue, percentage, transparent)
end
new(red, green, blue, percentage = 1, transparent = false) click to toggle source
# 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

Public Instance Methods

==(other) click to toggle source
# File lib/gauguin/color.rb, line 13
def ==(other)
  self.class == other.class && self.to_key == other.to_key
end
Also aliased as: eql?
distance(other_color) click to toggle source
# File lib/gauguin/color.rb, line 28
def distance(other_color)
  (self.to_lab - other_color.to_lab).r
end
eql?(other)
Alias for: ==
hash() click to toggle source
# File lib/gauguin/color.rb, line 19
def hash
  self.to_key.hash
end
inspect() click to toggle source
# File lib/gauguin/color.rb, line 63
def inspect
  msg = "#{to_s}[#{percentage}]"
  if transparent?
    msg += "[transparent]"
  end
  msg
end
similar?(other_color) click to toggle source
# 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() click to toggle source
# File lib/gauguin/color.rb, line 46
def to_a
  to_rgb + [self.percentage, self.transparent]
end
to_key() click to toggle source
# File lib/gauguin/color.rb, line 55
def to_key
  to_rgb + [self.transparent]
end
to_lab() click to toggle source
# 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() click to toggle source
# File lib/gauguin/color.rb, line 42
def to_rgb
  [self.red, self.green, self.blue]
end
to_s() click to toggle source
# File lib/gauguin/color.rb, line 59
def to_s
  "rgb(#{self.red}, #{self.green}, #{self.blue})"
end
to_vector() click to toggle source
# File lib/gauguin/color.rb, line 38
def to_vector
  ColorSpace::RgbVector[*to_rgb]
end
transparent?() click to toggle source
# File lib/gauguin/color.rb, line 71
def transparent?
  self.transparent
end