2013-02-10 23:16:30 +00:00
|
|
|
<!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">
|
2013-02-10 23:16:30 +00:00
|
|
|
hammer down
|
|
|
|
</canvas>
|
2013-02-10 23:22:52 +00:00
|
|
|
<canvas id="tutorial1" width="150" height="150">
|
|
|
|
rabbit ears
|
|
|
|
</canvas>
|
2013-02-10 23:16:30 +00:00
|
|
|
<script type="text/javascript">
|
2013-02-10 23:22:52 +00:00
|
|
|
function draw0() {
|
|
|
|
var canvas = document.getElementById('tutorial0');
|
2013-02-10 23:16:30 +00:00
|
|
|
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);
|
2013-02-10 23:16:30 +00:00
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|