这到底是怎么回事?
为什么混合突然停止于255,214,214,255?这是预期的行为吗?
我以为它最终会击中255,255,255,255,但事实并非如此。它甚至还没有接近。红色矩形从一开始就不会消失为白色,它255,214,214,255永远保持彩色。
const ctx = document.querySelector('canvas').getContext('2d');
// draw "red"
ctx.fillStyle = 'red';
ctx.fillRect(0, 0, 300, 200);
function loop() {
// log new colors
if (getCurrentColor() !== loop.lastColor) {
console.log(loop.lastColor = getCurrentColor());
}
// draw "transparent white" repeatedly
ctx.fillStyle = 'rgba(255,255,255,0.01)';
ctx.fillRect(0, 0, 300, 200);
// schedule next iteration
requestAnimationFrame(loop);
}
loop(); // start loop
function getCurrentColor() {
return ctx.getImageData(0, 0, 1, 1).data.join(',');
}Run Code Online (Sandbox Code Playgroud)
<!DOCTYPE html>
<html>
<head></head>
<body>
<canvas width="300" height="200"></canvas>
</body>
</html> …Run Code Online (Sandbox Code Playgroud)