I want to represent a range of numerical values (approx: 0 -> 1000) using colors such that there is an visually obvious gradient between low and high values, with similar values being visually similar. Kind of like astronomers use to show differences and similarities on IR or UV photographs.
Should I use a lookup table (and is there one available)?
Or can I get away with a formula to map them (and does anyone know such a formula)?
Update: I finally found a reference for what astronomers use--it's call a Color Ramp, and there is a standard one.
The reference for anyone following along is Color Ramp and there is an implementation in C at C source.
I've translated this into Perl as:
sub colorRamp { my( $v, $vmin, $vmax ) = @_; my( $r, $g, $b ) = (1) x 3; $v = $vmax if $v > $vmax; $v = $vmin if $v < $vmin; ## Uncomment below to invert the color range ## so that small numbers are hot (red) ## and high numbers are cold (blue) ## $v = $vmax + $vmin - $v; my $dv = $vmax - $vmin; if( $v < ( $vmin + 0.25*$dv ) ) { $r = 0; $g = 4 * ($v - $vmin) / $dv; } elsif( $v < ( $vmin + 0.5 * $dv ) ) { $r = 0; $b = 1 + 4 * ($vmin + 0.25 * $dv - $v) / $dv; } elsif( $v < ( $vmin + 0.75 * $dv ) ) { $r = 4 * ($v - $vmin - 0.5 * $dv) / $dv; $b = 0; } else { $g = 1 + 4 * ($vmin + 0.75 * $dv - $v) / $dv; $b = 0; } ## Convert the 0->1 range rgb values to 0->255 ## and output as a web/tk style "#rrggbb" hex string return sprintf "#%02x%02x%02x", $r*255, $g*255, $b*255; }
In reply to A hierarchy of color (intensity)? by BrowserUk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |