Created
March 17, 2014 12:49
-
-
Save kalmanolah/9598630 to your computer and use it in GitHub Desktop.
A color generator which allows mixing with white to produce colors that are pleasing to the eye.
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 generateColor(mix, mixColor) { | |
if (!mixColor) { | |
mixColor = { | |
red: 255, | |
green: 255, | |
blue: 255 | |
}; | |
} | |
var red = Math.floor((Math.random()*256)), | |
green = Math.floor((Math.random()*256)), | |
blue = Math.floor((Math.random()*256)); | |
if (mix) { | |
red = Math.round((red + mixColor.red) / 2); | |
green = Math.round((green + mixColor.green) / 2); | |
blue = Math.round((blue + mixColor.blue) / 2); | |
} | |
return { | |
red: red, | |
green: green, | |
blue: blue, | |
getRGB: function () { | |
return 'rgb('+this.red+','+this.green+','+this.blue+')'; | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment