Module: Abachrome::PaletteMixins::Interpolate
- Defined in:
- lib/abachrome/palette_mixins/interpolate.rb
Instance Method Summary collapse
Instance Method Details
#interpolate(count_between = 1) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/abachrome/palette_mixins/interpolate.rb', line 24 def interpolate(count_between = 1) return self if count_between < 1 || size < 2 new_colors = [] @colors.each_cons(2) do |color1, color2| new_colors << color1 step = AbcDecimal("1.0") / AbcDecimal(count_between + 1) (1..count_between).each do |i| amount = step * i new_colors << color1.blend(color2, amount) end end new_colors << last self.class.new(new_colors) end |
#interpolate!(count_between = 1) ⇒ Object
42 43 44 45 46 |
# File 'lib/abachrome/palette_mixins/interpolate.rb', line 42 def interpolate!(count_between = 1) interpolated = interpolate(count_between) @colors = interpolated.colors self end |