我们即使没有自己写过canvas的基础代码,但应该都知道它的几个点、线、曲线...等的几个canvas操作代码(moveTo()、lineTo()等),一搜,就定位到basicDot、basicLine、basicCurve的几个方法,然后这样这样子一改:
var basicDot = function(ctx, y, x, size){
var fillStyle = ctx.fillStyle;
ctx.fillStyle = ctx.strokeStyle;
ctx.fillRect(x + size / -2 , windowWidth - y + size / -2, size, size);
ctx.fillStyle = fillStyle;
}
, basicLine = function(ctx, starty, startx, endy, endx){
ctx.beginPath();
ctx.moveTo(startx, windowWidth - starty);
ctx.lineTo(endx, windowWidth - endy);
ctx.closePath();
ctx.stroke();
}
, basicCurve = function(ctx, starty, startx, endy, endx, cp1y, cp1x, cp2y, cp2x){
ctx.beginPath();
ctx.moveTo(startx, windowWidth - starty);
ctx.bezierCurveTo(cp1x, windowWidth - cp1y, cp2x, windowWidth - cp2y, endx, windowWidth - endy);
ctx.closePath();
ctx.stroke();
}