Module: ChunkyPNG::Color

Defined in:
lib/chunky_png_patch/color.rb

Class Method Summary collapse

Class Method Details

.distance(pixel, poxel) ⇒ Object

The modular distance, as the hue is circular



10
11
12
13
# File 'lib/chunky_png_patch/color.rb', line 10

def self.distance(pixel, poxel)
  hue_pixel, hue_poxel = hue(pixel), hue(poxel)
  [(hue_pixel - hue_poxel) % 360, (hue_poxel - hue_pixel) % 360].min
end

.hue(pixel) ⇒ Object



3
4
5
6
7
# File 'lib/chunky_png_patch/color.rb', line 3

def self.hue(pixel)
  r, g, b = r(pixel), g(pixel), b(pixel)
  return 0 if r == b and b == g
  ((180 / Math::PI * Math.atan2((2 * r) - g - b, Math.sqrt(3) * (g - b))) - 90) % 360
end