Sha256: 5f7f3ed3d11f7072c1aafee128c78c95d09da24c54681a1bb01cb78f0aef2471
Contents?: true
Size: 891 Bytes
Versions: 1
Compression:
Stored size: 891 Bytes
Contents
require 'rubygems' require 'interpolate' require 'color' # a nice weathermap-style color gradient points = { 1 => Color::RGB::Cyan, 2 => Color::RGB::Lime, # 3 => ? (between Lime and Yellow; Interpolate will figure it out) 4 => Color::RGB::Yellow, 5 => Color::RGB::Orange, 6 => Color::RGB::Red, 7 => Color::RGB::Magenta, 8 => Color::RGB::White, } # we need to implement a blending function in order for Interpolate::Points to # work properly # # fortunately, Color::RGB includes +mix_with+, which is almost functionally # identical to what we need gradient = Interpolate::Points.new(points) gradient.blend_with {|color, other, balance| color.mix_with(other, balance * 100.0) } # what are the colors of the gradient from 1 to 8 # in increments of 0.2? (1).step(7, 0.2) do |value| color = gradient.at(value) puts "A value of #{value.round(3)} means #{color.html}" end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
interpolate-0.3.0 | examples/colors.rb |