Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@rista404
Last active April 20, 2018 00:24
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 rista404/11946f90eba3806c79f3f6465b711ccb to your computer and use it in GitHub Desktop.
Save rista404/11946f90eba3806c79f3f6465b711ccb to your computer and use it in GitHub Desktop.
Some codegolfing I did, along with the progress
// random hex
'#'+Math.random().toString(16).slice(-6)
'#'+(~~(Math.random()*0xffffff)).toString(16)
'#'+parseInt(Math.random()*0xffffff).toString(16)
// random rgb
r=_=>(Math.random()*255|0),`rgb(${[r(),r(),r()]})`
// random rgba
r=_=>(Math.random()*255|0),`rgba(${[r(),r(),r()]},1)`
r=_=>(Math.random()*255|0)+',',`rgba(${r()+r()+r()}1)`
r=Math.random,a=_=>(r()*255|0)+',',`rgba(${a()+a()+a()}1)`
r=Math.random,a=_=>~~(r()*255)+',',`rgba(${a()+a()+a()}1)`
r=Math.random,a=_=>~~(r()*255)+',',x=a()+a()+a(),`rgba(${x}1)`
// rgb to hex - es6 version of https://gist.github.com/jed/983535
(a,b,c)=>"#"+((256+a<<8|b)<<8|c).toString(16).slice(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment