总结:
HTML—创建一个画布:
<canvas id="canvas"></canvas>
JavaScript—
//创建绘图变量
var canvas = document.getElementById('canvas');
//获取绘图上下文环境
var context = canvas.getContext("2d");
//使用context进行绘制canvas常用的属性:
canvas.width
canvas.height
canvas.getContext('2d')canvas构成线条使用方法:
moveTo(x, y); lineTo(x, y); beginPath(); closePath();
canvas具体状态设置:
lineWidth — 线条 strokeStyle — 线条样式 fillStyle — 填充样式 stroke() — 函数 绘制边框 fill() — 函数 进行填充
简易函数—矩形
rect(x, y, width, height) — 绘制矩形边框路径 fillRect(x, y, width, height) — 具体填充矩形 strokeRect(x, y, width, height) — 绘制带有边框矩形
本章小结:lineWidth strokeStyle fillStyle stroke fill