My canvas is used for drawing and animating some lines in different colors, which could look like this: 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);
When those lines intersect, I want their colors being multiplied (like the Photoshop filter).
I found a nice explanation on how to do this pixelwise, but since my canvas will hold an animation I wonder if there is a better option than iterating over every pixel and calculating the color value manually in every loop.