第一课(简单介绍)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<style type="text/css">
body {
text-align: center;
padding-top: 20px;
}
canvas {
box-shadow: 0 0 10px #333;
margin: 0 auto;
}
</style>
<body onload="draw()">
<canvas id="canvas" width="800" height="600">
你的浏览器太low了,请更新~~~
</canvas>
</body>
<script>
function draw() {
var canvas = document.getElementById('canvas');
if (canvas.getContext) {
var ctx = canvas.getContext('2d');
ctx.fillStyle = 'rgb(200,0,0)'
ctx.fillRect(10,10,350,300)
ctx.fillStyle= 'rgba(0,0,200,0.5)'
ctx.fillRect(30,30,350,300)
ctx.strokeStyle= 'rgb(200,0,0)'
ctx.strokeRect(10,10,350,300)
ctx.strokeStyle= 'rgba(0,0,200,0.5)'
ctx.strokeRect(30,30,350,300)
}
}
</script>
</html>
第二课(绘制空心矩形)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<style type="text/css">
body {
text-align: center;
padding-top: 20px;
}
canvas {
box-shadow: 0 0 10px #333;
margin: 0 auto;
}
</style>
<body onload="draw()">
<canvas id="canvas" width="800" height="600">
你的浏览器太low了,请更新~~~
</canvas>
</body>
<script>
function draw() {
var canvas = document.getElementById('canvas');
if (canvas.getContext) {
var ctx = canvas.getContext('2d');
ctx.fillRect(25,25,100,100);
ctx.clearRect(45,45,60,60);
ctx.strokeRect(50,50,50,50)
}
}
</script>
</html>
第三课(绘制三角形)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<style type="text/css">
body {
text-align: center;
padding-top: 20px;
}
canvas {
box-shadow: 0 0 10px #333;
margin: 0 auto;
}
</style>
<body onload="draw()">
<canvas id="canvas" width="800" height="600">
你的浏览器太low了,请更新~~~
</canvas>
</body>
<script>
function draw() {
var canvas = document.getElementById('canvas')