Created
September 7, 2016 15:19
-
-
Save fredmaggiowski/269f027af7c8b23bd963e40fd739cb8e to your computer and use it in GitHub Desktop.
A basic function to transform a float into a RGB value (from green to red)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function f2R(f) { | |
var r = 255 | |
var g = 255 | |
var b = 0 | |
var x = Math.abs(f - 0.5); | |
var i = Math.ceil(600 * (0.5 - x)); | |
// range between green and yellow | |
if (f < 0.4) { | |
r = i | |
} | |
// range between yellow and red | |
if (f >= 0.4) { | |
g = i | |
} | |
return "rgb(" + r + "," + g + "," + b + ")"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment