I’m creating a “bubble generator” as a background effect that will run on a page. The generator works fine, but it slows down, a lot after a short while.
demo: http://jsfiddle.net/Dud2q/
I set the demo to run at 1ms intervals so it’s easy to see the slow-down when you re-launch the fiddle (especially if you make the result window large).
The issue is that I have thousands of calls to this code (one for each bubble):
ctx.beginPath();
ctx.moveTo(x, y);
ctx.lineTo(x+1, y+1);
ctx.stroke();
Does anyone know of a quicker way to draw one pixel in canvas?
Also, if anyone wants to take a stab at making the bubbles more realistic, I wouldn’t complain 🙂
Instead of drawing the bubbles one-by-one, how about drawing the at once? i.e. moving the
ctx.beginPath()andctx.stroke()out of the loop? It looks a lot faster on Firefox. 🙂It does slow down when there are more bubbles however.