Created
April 15, 2011 09:02
-
-
Save manuelvanrijn/921430 to your computer and use it in GitHub Desktop.
generate random greenish color
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 randomGreenishColor(i, total) { | |
var g = randomFromTo(128, 255); | |
var r = randomFromTo(0, g-50); | |
var b = randomFromTo(0, g-50); | |
return rgbToHex(r,g,b); | |
} | |
function rgbToHex(r, g, b) { | |
return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b); | |
} | |
function componentToHex(c) { | |
var hex = c.toString(16); | |
return hex.length == 1 ? "0" + hex : hex; | |
} | |
function randomFromTo(from, to) { | |
return Math.floor(Math.random() * (to - from + 1) + from); | |
} | |
/* HTML */ | |
var total = 255; | |
for(var i=0; i< total; i++) { | |
var color = randomGreenishColor(i, total); | |
// TODO: do something with it. | |
// ex: $("body").append("<div style='background-color: "+color+"'></div>"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment