Class: ColorExtract::Palette

Inherits:
Object
  • Object
show all
Includes:
ColorUtil
Defined in:
lib/color_extract/palette.rb

Constant Summary

Constants included from ColorUtil

ColorUtil::K, ColorUtil::X, ColorUtil::Y, ColorUtil::Z

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ColorUtil

#darken, #darken!, #dither, #hue_similarity, #lighten, #lighten!, #pure, #readable_textcolor, #reverse_color, #rgb2lab, #rgb_xyz, #similarity, #xyz_lab

Constructor Details

#initialize(file = nil) ⇒ Palette

Returns a new instance of Palette.



17
18
19
# File 'lib/color_extract/palette.rb', line 17

def initialize( file = nil )
  @analytics = Analytics.new( file ) if file
end

Instance Attribute Details

#main_colorObject

Returns the value of attribute main_color.



15
16
17
# File 'lib/color_extract/palette.rb', line 15

def main_color
  @main_color
end

#max_pri_brightnessObject

Returns the value of attribute max_pri_brightness.



15
16
17
# File 'lib/color_extract/palette.rb', line 15

def max_pri_brightness
  @max_pri_brightness
end

#raw_colorsObject

Returns the value of attribute raw_colors.



15
16
17
# File 'lib/color_extract/palette.rb', line 15

def raw_colors
  @raw_colors
end

Class Method Details

.from_colors(colors) ⇒ Object



8
9
10
11
12
# File 'lib/color_extract/palette.rb', line 8

def from_colors( colors )
  new.tap do |palette|
    palette.raw_colors = colors.to_a
  end
end

Instance Method Details

#palette(accent_seed: nil) ⇒ Object

目前只生成一种配色方案



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

def palette( accent_seed: nil )
  palettes( count: 1, accent_seed: accent_seed ).first
end

#palettes(opts = {}) ⇒ Object



26
27
28
29
# File 'lib/color_extract/palette.rb', line 26

def palettes( opts={} )
  @raw_colors ||= @analytics.valuable_colors.map {|per, c| c }
  @palettes   ||= gen_palettes( opts )
end