Skip to content

Instantly share code, notes, and snippets.

@mdamien
Created April 29, 2014 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdamien/a060ed8a9e38471545ac to your computer and use it in GitHub Desktop.
Save mdamien/a060ed8a9e38471545ac to your computer and use it in GitHub Desktop.
Rainbow
function rainbow(step) {
var r, g, b;
var h = step / 70;
var i = ~~(h * 6);
var f = h * 6 - i;
var q = 1 - f;
switch (i % 6) {
case 0:
r = 1, g = f, b = 0;
break;
case 1:
r = q, g = 1, b = 0;
break;
case 2:
r = 0, g = 1, b = f;
break;
case 3:
r = 0, g = q, b = 1;
break;
case 4:
r = f, g = 0, b = 1;
break;
case 5:
r = 1, g = 0, b = q;
break;
}
var c = "#" + ("00" + (~~(r * 255)).toString(16)).slice(-2) + ("00" + (~~(g * 255)).toString(16)).slice(-2) + ("00" + (~~(b * 255)).toString(16)).slice(-2);
return (c);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment