Last active
September 15, 2015 13:11
-
-
Save imRohan/cb98975cb6019ce0a5d6 to your computer and use it in GitHub Desktop.
Random RGB Colour Generator
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
generateRandomColor: (mix) -> | |
red = Math.random() * 256 >> 0 | |
green = Math.random() * 256 >> 0 | |
blue = Math.random() * 256 >> 0 | |
if mix != null | |
red = (red + mix.red) / 2 >> 0 | |
green = (green + mix.green) / 2 >> 0 | |
blue = (blue + mix.blue) / 2 >> 0 | |
rr = red.toString(16) | |
if rr.length == 1 | |
rr = '0' + rr[0] | |
gg = green.toString(16) | |
if gg.length == 1 | |
gg = '0' + gg[0] | |
bb = blue.toString(16) | |
if bb.length == 1 | |
bb = '0' + bb[0] | |
'#' + rr + gg + bb | |
generateRandomColor({red: 230, green: 230, blue: 230}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment