Skip to content

Instantly share code, notes, and snippets.

@borgateo
Created May 12, 2016 12:19
Show Gist options
  • Save borgateo/9e6b382337810455735bb63db248d8ad to your computer and use it in GitHub Desktop.
Save borgateo/9e6b382337810455735bb63db248d8ad to your computer and use it in GitHub Desktop.
Hex random colors
<!DOCTYPE html>
<html>
<head>
<title>Math.floor(Math.random() * 16777215).toString(16)</title>
</head>
<body>
<script type="text/javascript">
var r = Math.random;
var c = document.createElement('canvas');
var w = window.innerWidth;
var h = window.innerHeight;
var t = c.getContext('2d');
c.width = w; c.height = h;
var color;
document.body.appendChild( c );
setInterval( function() {
color = Math.floor( r() * 16777215 ).toString( 16 );
t.fillStyle = '#' + color;
t.fillRect( 0, 0, w, h );
}, 1000);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment