You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.2 KiB
HTML

5 years ago
<!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>