Module: ColorMath::Color

Included in:
HSL, RGB
Defined in:
lib/colormath/color.rb

Overview

Color can be mixed into any class that responds to red, green, and blue, where 0 <= c <= 1

Constant Summary collapse

EPSILON =
1/256.0

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object

Returns true if the RGB components of the two colours differ by less than EPSILON, i.e. they are the same when represented in 8 bits.



11
12
13
14
15
16
# File 'lib/colormath/color.rb', line 11

def ==(other)
  deltas = [ other.red   - self.red,
             other.green - self.green,
             other.blue  - self.blue ].map{ |e| e.abs }
  deltas.max < EPSILON
end

#hexObject

The six-digit hexadecimal representation of the colour, e.g. “#cafe66”



20
21
22
# File 'lib/colormath/color.rb', line 20

def hex
  "#%02x%02x%02x" % [red * 0xff, green * 0xff, blue * 0xff]
end

#inspect(*args) ⇒ Object



24
25
26
# File 'lib/colormath/color.rb', line 24

def inspect(*args)
  "<%s r=%0.3f g=%0.3f b=%0.3f>" % [self.class.to_s, red, green, blue]
end