O'Reilly logo

HTML5 Canvas Cookbook by Eric Rowell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating microscopic life forms

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.

Creating microscopic life forms

How to do it...

Follow these steps to create wiggling microbes moving inside the canvas:

  1. Link to the Animation class:
    <head>
        <script src="animation.js">
        </script>
  2. 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)]; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required