This animation makes my fans spin up after several seconds, and it seems to have a sub-par framerate. I am trying to understand why, and optimize its performance.
The animation function (this is the main part of the code):
function animate() {
t++
ctx.clearRect(0, 0, c.width, c.height);
for (var i = 40; i < max; i+= 60) {
var radius = Math.floor(i+Math.sin(t/10)*10)
ctx.beginPath()
ctx.arc(center[0], center[1], radius, 0, 2 * Math.PI, false)
ctx.closePath()
ctx.stroke()
}
requestAnimationFrame(animate)
}
The for
loop draws the minimum number of circles needed in order to fill the screen. Their radius pulses in and out with a sine function based on the 't' variable.
Am I doing something wrong?