2. The <canvas> Element
<!doctype html>
<html>
<head>
<title>Canvas is awesome!</title>
</head>
<body>
<canvas width="500" height="500">
Sorry, your browser does not support canvas :(
</canvas>
</body>
</html>
22. In code
function drawSquare(x, y) {
ctx.fillRect(x, y, 100, 100);
}
parameterize the function so
that we can draw the square
in different locations
23. In code
var x = 50, y = 50;
function clearScreen() {...}
function drawSquare(x, y) {...}
function draw() {
clearScreen();
drawSquare(x, y);
x = x + 5;
setTimeout(draw, 50);
}
draw();
24. Putting it all together
http://codepen.io/sethmcl/pen/duGsh