cavans实现清除圆形区域
1 touchmove: function(e) { 2 if (this.complete || this.disabled) { 3 return; 4 } 5 // ctx.globalCompositeOperation = 'destination-out'; 6 ctx.moveTo(this.startX, this.startY); 7 // ctx.beginPath(); 8 // ctx.arc(this.startX, this.startY, 20, 0, Math.PI * 20); 9 // ctx.fill(); 10 let stepClear = 1; // 剩餘清除的小矩形數 11 clearArc(this.startX, this.startY, this.touchSize/2); 12 // 清除出一個圓形區域 13 function clearArc(x, y, radius) { 14 var calcWidth = radius - stepClear; 15 var calcHeight = Math.sqrt(radius * radius - calcWidth * calcWidth); 16 17 var posX = x - calcWidth; 18 var posY = y - calcHeight; 19 20 var widthX = 2 * calcWidth; 21 var heightY = 2 * calcHeight; 22 if (stepClear <= radius) { 23 ctx.clearRect(posX, posY, widthX, heightY); 24 stepClear += 1; 25 clearArc(x, y, radius); 26 } 27 } 28 // ctx.clearRect(this.startX, this.startY, this.touchSize, this.touchSize); 29 ctx.draw(true); 30 //记录移动点位 31 this.startX = e.touches[0].x; 32 this.startY = e.touches[0].y; 33 }