Skip to content

Instantly share code, notes, and snippets.

@imRohan
Last active September 15, 2015 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imRohan/cb98975cb6019ce0a5d6 to your computer and use it in GitHub Desktop.
Save imRohan/cb98975cb6019ce0a5d6 to your computer and use it in GitHub Desktop.
Random RGB Colour Generator
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