Created
January 9, 2015 17:36
-
-
Save TiborUdvari/a94d8142353faf042464 to your computer and use it in GitHub Desktop.
Boilerplate code for canvas
This file contains hidden or 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>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