Have you ever seen microscopic life forms in a microscope and observed how they wiggle around? This recipe is inspired by the alien-like world of micro-organisms. In this recipe, we'll create 100 random microbes and let them loose in the canvas.
Follow these steps to create wiggling microbes moving inside the canvas:
Link to the
Animation
class:<head> <script src="animation.js"> </script>
Define the
getRandColor()
function that returns a random color:<script> function getRandColor(){ var colors = ["red", "orange", "yellow", "green", "blue", "violet"]; return colors[Math.floor(Math.random() * colors.length)]; }
Define the
getRandTheta()
function that returns a random theta:function getRandTheta(){ return Math.random() * 2 * Math.PI; }
Define the
updateMicrobes()
function that updatesmicrobe
objects by adding a new head segment with a randomly generated...