Class: Camalian::Palette
- Inherits:
-
Array
- Object
- Array
- Camalian::Palette
- Defined in:
- lib/camalian/palette.rb
Overview
Collection of colors with some useful features
Class Method Summary collapse
Instance Method Summary collapse
- #average_color ⇒ Object
- #light_colors(limit1, limit2) ⇒ Object
- #sort_by_hue ⇒ Object
- #sort_by_lightness ⇒ Object
- #sort_by_saturation ⇒ Object
- #sort_similar_colors ⇒ Object
- #to_hex ⇒ Object
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_color ⇒ Object
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_hue ⇒ Object
14 15 16 |
# File 'lib/camalian/palette.rb', line 14 def sort_by_hue Palette.new(sort_by(&:h).reverse) end |
#sort_by_lightness ⇒ Object
10 11 12 |
# File 'lib/camalian/palette.rb', line 10 def sort_by_lightness Palette.new(sort_by(&:l).reverse) end |
#sort_by_saturation ⇒ Object
22 23 24 |
# File 'lib/camalian/palette.rb', line 22 def sort_by_saturation Palette.new(sort_by(&:s).reverse) end |
#sort_similar_colors ⇒ Object
18 19 20 |
# File 'lib/camalian/palette.rb', line 18 def sort_similar_colors Palette.new(sort_by(&:hsv)) end |
#to_hex ⇒ Object
42 43 44 |
# File 'lib/camalian/palette.rb', line 42 def to_hex map(&:to_hex) end |