Last active
December 14, 2015 06:29
-
-
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
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
<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