Class: Camalian::Palette

Inherits:
Array
  • Object
show all
Defined in:
lib/camalian/palette.rb

Overview

Collection of colors with some useful features

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_hex(hex_values) ⇒ Object



6
7
8
# File 'lib/camalian/palette.rb', line 6

def self.from_hex(hex_values)
  new(hex_values.map { |v| Color.from_hex(v) })
end

Instance Method Details

#average_colorObject



26
27
28
29
30
31
32
33
# File 'lib/camalian/palette.rb', line 26

def average_color
  r = map(&:r).inject(&:+)
  g = map(&:g).inject(&:+)
  b = map(&:b).inject(&:+)
  size = self.size

  Color.new(r / size, g / size, b / size)
end

#light_colors(limit1, limit2) ⇒ Object



35
36
37
38
39
40
# File 'lib/camalian/palette.rb', line 35

def light_colors(limit1, limit2)
  min = [limit1, limit2].min
  max = [limit1, limit2].max
  table = dup
  Palette.new(table.delete_if { |color| color.l > max or color.l < min })
end

#sort_by_hueObject



14
15
16
# File 'lib/camalian/palette.rb', line 14

def sort_by_hue
  Palette.new(sort_by(&:h).reverse)
end

#sort_by_lightnessObject



10
11
12
# File 'lib/camalian/palette.rb', line 10

def sort_by_lightness
  Palette.new(sort_by(&:l).reverse)
end

#sort_by_saturationObject



22
23
24
# File 'lib/camalian/palette.rb', line 22

def sort_by_saturation
  Palette.new(sort_by(&:s).reverse)
end

#sort_similar_colorsObject



18
19
20
# File 'lib/camalian/palette.rb', line 18

def sort_similar_colors
  Palette.new(sort_by(&:hsv))
end

#to_hexObject



42
43
44
# File 'lib/camalian/palette.rb', line 42

def to_hex
  map(&:to_hex)
end