After seeing the last recipe, you might be thinking "Is there a limit to how many microbes we can animate?" The straightforward answer to this question is yes. As the 2D context of the HTML5 canvas is not hardware-accelerated, and as our animations are driven purely by JavaScript, there is definitely a point where the browser will start to choke if it's working overtime. To illustrate this, we can draw the FPS of our animation and observe the relationship between the number of microbes on the screen and the FPS value.
Follow these steps to stress the canvas and display the FPS:
Link to the
Animation
class:<head> <script src="animation.js"> </script>
Define the
drawFps()
function that draws the FPS value in the top-right corner of the canvas:function drawFps(anim, fps){ var canvas = anim.getCanvas(); var context = anim.getContext(); context.fillStyle...