为什么在这个例子中,clearRect() 和 fillRect() 的值相同时,clearRect() 没有完全清除 fillRect()?
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.fillStyle = "red";
setInterval(function(){
let rect = {x:Math.random()*c.width, y:Math.random()*c.height}
ctx.fillRect(rect.x, rect.y, 5, 5);
ctx.clearRect(rect.x, rect.y, 5,5);
},500)
<canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.</canvas>
Math.random()
生成的分数像素被抗锯齿处理了(在这种情况下是否是正确的术语?),但您无法对清除进行抗锯齿处理。 - Ry-