Skip to content

Instantly share code, notes, and snippets.

@TiborUdvari
Created January 9, 2015 17:36
Show Gist options
  • Save TiborUdvari/a94d8142353faf042464 to your computer and use it in GitHub Desktop.
Save TiborUdvari/a94d8142353faf042464 to your computer and use it in GitHub Desktop.
Boilerplate code for canvas
<html>
<head>
<title>Canvas starter</title>
<style type="text/css">
body{
margin: 0;
}
</style>
</head>
<body>
<canvas id = "canvas" style="background-color: red;"></canvas>
<script type="text/javascript">
var canvas = document.getElementById('canvas');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
var c = canvas.getContext('2d');
c.fillStyle = "#ffffff";
var x = 0;
function draw()
{
c.clearRect(0, 0, window.innerWidth, window.innerHeight);
x += 1;
c.beginPath();
c.rect(x, 10, 20, 20);
c.stroke();
c.closePath();
requestAnimationFrame(draw);
}
draw();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment