1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
<!doctype html>
<html>
<head>
<title>canvas.js | basics (1)</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="../../pattern/canvas.js"></script>
<script>
function setup(canvas) {
// The setup() function is executed once, before the animation starts.
// This is a good place to load images, or set the canvas size.
canvas.size(500, 500);
}
function draw(canvas) {
// The draw() function is executed each animation frame.
// Call canvas.clear() to remove the previous frame.
// Draw a red rotating rectangle.
canvas.clear();
translate(250, 250);
rotate(canvas.frame);
rect(-150, -150, 300, 300, {fill: color(1,0,0,1)});
}
window.onload = function() {
// Attach setup() and draw() to the <canvas> and start the animation.
// In the next example we'll see a shorter syntax,
// where this is done automatically for you.
canvas = new Canvas(document.getElementById("canvas1"));
canvas.setup = setup;
canvas.draw = draw;
canvas.run();
}
</script>
</head>
<body>
<!-- The HTML <canvas> element targeted by the Canvas object above. -->
<canvas id="canvas1" width="500px" height="500px"></canvas>
</body>
</html>
|