Created
September 11, 2015 02:58
-
-
Save bkardell/0a7d78e16c2438f21ee9 to your computer and use it in GitHub Desktop.
A series of functions to auto-generate some interesting paletes for use with http://make8bitart.com/.
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
| function componentToHex(c) { | |
| var hex = c.toString(16); | |
| return hex.length == 1 ? "0" + hex : hex; | |
| } | |
| function rgbToHex(color) { | |
| return componentToHex(color.red) + componentToHex(color.green) + componentToHex(color.blue); | |
| } | |
| function getRandomInt(min, max) { | |
| return Math.floor(Math.random() * (max - min)) + min; | |
| } | |
| function generateRandomColor(mix) { | |
| var m = mix || {}, | |
| color = { | |
| red: getRandomInt(0,256), | |
| green: getRandomInt(0,256), | |
| blue: getRandomInt(0,256) | |
| }; | |
| // mix the color | |
| color.red = !m.red ? color.red : Math.floor((color.red + (m.red)) / 2); | |
| color.green = !m.green ? color.green : Math.floor((color.green + (m.green)) / 2); | |
| color.blue = !m.blue ? color.blue : Math.floor((color.blue + (m.blue)) / 2); | |
| return color; | |
| } | |
| function generateRandomPalette(size, base) { | |
| var buff = [], s = size || 24, b = base || generateRandomColor(); | |
| for (var i=0; i < s; i++) { | |
| b = generateRandomColor(b); | |
| buff.push("rando " + i + "," + rgbToHex(b)); | |
| } | |
| return buff.join("\n"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment