56 lines
1.5 KiB
HTML
56 lines
1.5 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>MDN Canvas Tutorial</title>
|
|
<style type="text/css">
|
|
canvas {
|
|
border: 1px solid black;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<canvas id="tutorial0" width="150" height="150"></canvas>
|
|
<canvas id="tutorial1" width="150" height="150"></canvas>
|
|
<canvas id="tutorial2" width="150" height="150"></canvas>
|
|
<script type="text/javascript">
|
|
function draw0() {
|
|
var ctx = document.getElementById('tutorial0').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);
|
|
}
|
|
|
|
function draw1() {
|
|
var ctx = document.getElementById('tutorial1').getContext('2d');
|
|
|
|
ctx.fillRect(25, 25, 100, 100);
|
|
ctx.clearRect(45, 45, 60, 60);
|
|
ctx.strokeRect(50, 50, 50, 50);
|
|
}
|
|
|
|
function draw2() {
|
|
var ctx = document.getElementById('tutorial2').getContext('2d');
|
|
|
|
ctx.beginPath();
|
|
ctx.arc(75, 75, 50, 0, Math.PI*2, true);
|
|
ctx.moveTo(110, 75);
|
|
ctx.arc(75, 75, 35, 0, Math.PI, false);
|
|
ctx.moveTo(65, 65);
|
|
ctx.arc(60, 65, 5, 0, Math.PI*2, true);
|
|
ctx.moveTo(95, 65);
|
|
ctx.arc(90, 65, 5, 0, Math.PI*2, true);
|
|
ctx.stroke();
|
|
}
|
|
|
|
window.addEventListener('load', function() {
|
|
draw0();
|
|
draw1();
|
|
draw2();
|
|
}, false);
|
|
</script>
|
|
</body>
|
|
</html>
|