[英]How to multiply colors of simple shapes in an animated canvas
我的画布用于以不同的颜色绘制和设置一些线条的动画,如下所示: http : //jsfiddle.net/swknhg3t/
HTML:
<canvas id="myCanvas" width="400px" height="400px"></canvas>
JavaScript的:
var elem = document.getElementById('myCanvas');
var c = elem.getContext('2d');
var count = 0;
function draw() {
c.save();
c.clearRect(0, 0, 400, 400);
// red
c.beginPath();
c.moveTo(20, 50);
c.lineCap = "round";
c.lineWidth = 20;
c.lineTo(380, 50);
c.strokeStyle = "#f00";
c.stroke();
// green
c.beginPath();
c.moveTo(20, 350);
c.lineCap = "round";
c.lineWidth = 20;
c.lineTo(380, 350);
c.strokeStyle = "#0f0";
c.stroke();
// blue
c.translate(200, 200);
c.rotate(count * (Math.PI / 180));
c.beginPath();
c.moveTo(0, 0);
c.lineCap = "round";
c.lineWidth = 20;
c.lineTo(180, 0);
c.strokeStyle = "#00f";
c.stroke();
c.restore();
count++;
}
setInterval(draw, 20);
当这些线相交时,我希望它们的颜色成倍增加(例如Photoshop滤镜)。
我找到了关于如何按像素进行此操作的很好的解释 ,但是由于我的画布上将保留动画,所以我想知道是否有比迭代每个像素并在每个循环中手动计算颜色值更好的选择。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.