require 'rubygems' require 'interpolate' require 'color' # 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 } # Color objects can't interpolate themselves right out of the box, # so rather than monkey patch the :interpolate method, you can pass # a block with the instantiation of a new Interpolation object gradient = Interpolation.new(points) do |left, right, balance| left.mix_with(right, balance * 100.0) end # 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