Sha256: feebc064120480ab37bf78832aafde80481e472e3ccae1a14e0c1a2e8af81922

Contents?: true

Size: 755 Bytes

Versions: 3

Compression:

Stored size: 755 Bytes

Contents

require 'rubygems'
require 'interpolate'
require 'color'


# we need to implement :interpolate for Color::RGB
# in order for Interpolation to work
class Color::RGB
  def interpolate(other, balance)
    mix_with(other, balance * 100.0)
  end
end

# a nice weathermap-style color gradient
points = {
  0 => Color::RGB::White,
  1 => Color::RGB::Lime,
# 2 => ? (something between Lime and Yellow)
  3 => Color::RGB::Yellow,
  4 => Color::RGB::Orange,
  5 => Color::RGB::Red,
  6 => Color::RGB::Magenta,
  7 => Color::RGB::DarkGray
}


gradient = Interpolation.new(points)

# what are the colors of the gradient from 0 to 7
# in increments of 0.2?
(0).step(7, 0.2) do |value|
  color = gradient.at(value)
  puts "A value of #{value} means #{color.html}"
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
interpolate-0.2.1 examples/colors.rb
interpolate-0.2.0 examples/colors.rb
interpolate-0.2.2 examples/colors.rb