Skip to content

Instantly share code, notes, and snippets.

@kalmanolah
Created March 17, 2014 12:49
Show Gist options
  • Save kalmanolah/9598630 to your computer and use it in GitHub Desktop.
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.
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