You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
box-o-sand/html5/canvas/mdn-tutorial.html

52 lines
1.2 KiB

<!DOCTYPE html>
<html>
<head>
<title>MDN Canvas Tutorial</title>
<style type="text/css">
canvas {
border: 1px solid black;
}
</style>
</head>
<body>
12 years ago
<canvas id="tutorial0" width="150" height="150">
hammer down
</canvas>
12 years ago
<canvas id="tutorial1" width="150" height="150">
rabbit ears
</canvas>
<script type="text/javascript">
12 years ago
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);
}
12 years ago
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>