Reputation: 177
I have while loop drawing circles one by one:
actx.shadowColor = 'rgba(0, 0, 0, 1)';
while (len--) {
var point = data[len];
actx.beginPath();
actx.arc(point[0] - 15000, point[1] - 15000, 10, 0, Math.PI * 2);
actx.closePath();
actx.fill();
}
It seems a little bit slow for me, so I am thinking how it could be optimized. I have found that the fill()
function takes the longest, so I have tried put it after the loop, but it draws only the last circle.
Upvotes: 0
Views: 69
Reputation: 105015
Some optimizations:
Refactored code:
// test data
var data=[];
for(var i=0;i<100;i++){data.push([i+15000+30,i+15000+30]);}
// calculate PI2 outside the loop instead of every time in the loop
var PI2=Math.PI*2;
actx.shadowColor = 'rgba(0, 0, 0, 1)';
// beginpath once outside the loop
actx.beginPath();
var len=data.length;
while (len--) {
var point = data[len];
// draw
actx.arc(point[0]-15000, point[1]-15000,10,0,PI2);
// closepath will close the current circle's subpath
actx.closePath();
}
// just fill once when done drawing
actx.fill();
Upvotes: 1