Skip to content

Instantly share code, notes, and snippets.

@nelsonic
Last active December 14, 2015 06:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nelsonic/5042941 to your computer and use it in GitHub Desktop.
Save nelsonic/5042941 to your computer and use it in GitHub Desktop.
Disco Squares CoffeeScript HTML5 Canvas Just copy paste the script into an .html file and see. A variation on the disco on p.21 of Jump Start CoffeeScript by Earle Castledine
<html>
<head>
<title> Disco Squares</title>
</head>
<body>
<style type="text/css">
html, body, #game {
width: 100%;
height: 100%;
margin: 1px;
}
</style>
<canvas id="game"></canvas>
<script src="http://coffeescript.org/extras/coffee-script.js"></script>
<script type="text/coffeescript">
ctx = document
.getElementById("game")
.getContext("2d")
noise = ->
for x in [0..20]
for y in [0..10]
color = Math.floor(Math.random() * 360)
ctx.fillStyle = "hsl(#{color}, 60%, 50%)"
sq = 15 # pixels
ctx.fillRect x * sq, y * sq, sq-1, sq-1
setInterval noise, 100
# this is
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment