Last active
November 23, 2015 23:16
-
-
Save jeshuamaxey/8a64af974e2b428d9e33 to your computer and use it in GitHub Desktop.
takes a value from 0-1 and returns an rgb color string
This file contains hidden or 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
/** | |
* takes a value from 0-1 and returns an rgb color string | |
*/ | |
function floatToColor(val) { | |
var c = Math.floor(5*255*val); | |
var r = 255, g = 255, b = 255; | |
while(c > 0) { | |
if(r!=0 && g==255 && b==255) r--; //rgb(255,255,255) -> rgb(0,255,255) | |
if(r==0 && g==255 && b!=0) b--; //rgb(0,255,0) -> rgb(0,255,0) | |
if(r!=255 && g==255 && b==0) r++; //rgb(0,255,0) -> rgb(255,255,0) | |
if(r==255 && g!=0 && b==0) g--; //rgb(255,255,0) -> rgb(255,0, 0) | |
if(r==255 && g==0 && b!=255) b++; //rgb(255,0,0) -> rgb(255,0,255) | |
c--; | |
} | |
var color = 'rgb(' + r + ',' + g + ',' + b + ')'; | |
return color; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment