基础矩形
rect(x,y,width,height)
基础画法
const res = main.getContext("2d");
res.fillRect(0, 0, 300, 300); // 填满
res.strokeRect(290, 290, 300, 300); // 线
组合画法
const res = main.getContext("2d")
res.beginPath()
res.rect(0,0,300,300)
res.fill()
res.closePath()
res.beginPath()
res.rect(290, 290, 300, 300)
res.stroke()
res.closePath()
清除画法
res.clearRect(0,0,res.clientWidth,res.clientHeight)
零碎
// 连续绘制
res.beginPath()
res.rect(290, 290, 300, 300)
moveTo(x,y) ---> 移动不连续的点继续绘制
res.stroke()
res.closePath()
// 绘制直线
res.lineTo(10,10)