box-o-sand/html5/canvas/mdn-tutorial.html

52 lines
1.2 KiB
HTML
Raw Normal View History

<!DOCTYPE html>
<html>
<head>
<title>MDN Canvas Tutorial</title>
<style type="text/css">
canvas {
border: 1px solid black;
}
</style>
</head>
<body>
2013-02-10 23:22:52 +00:00
<canvas id="tutorial0" width="150" height="150">
hammer down
</canvas>
2013-02-10 23:22:52 +00:00
<canvas id="tutorial1" width="150" height="150">
rabbit ears
</canvas>
<script type="text/javascript">
2013-02-10 23:22:52 +00:00
function draw0() {
var canvas = document.getElementById('tutorial0');
if (!canvas.getContext) {
return;
}
var ctx = canvas.getContext('2d');
ctx.fillStyle = 'rgb(200, 0, 0)';
ctx.fillRect(10, 10, 55, 50);
ctx.fillStyle = 'rgba(0, 0, 200, 0.5)';
ctx.fillRect(30, 30, 55, 50);
}
2013-02-10 23:22:52 +00:00
function draw1() {
var canvas = document.getElementById('tutorial1');
if (!canvas.getContext) {
return;
}
var ctx = canvas.getContext('2d');
ctx.fillRect(25, 25, 100, 100);
ctx.clearRect(45, 45, 60, 60);
ctx.strokeRect(50, 50, 50, 50);
}
window.addEventListener('load', function() {
draw0();
draw1();
}, false);
</script>
</body>
</html>