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

Animating mechanical gears

For the mechanics and engineers out there, this one's for you. In this recipe, we'll create a system of interconnected rotating gears.

Animating mechanical gears

How to do it...

Follow these steps to animate a system of interconnected gears:

  1. Link to the Animation class:
    <head>
        <script src="animation.js">
        </script>
  2. Define the constructor for the Gear class:
        <script> function Gear(config){ this.x = config.x; this.y = config.y; this.outerRadius = config.outerRadius; this.innerRadius = config.innerRadius; this.holeRadius = config.holeRadius; this.numTeeth = config.numTeeth; this.theta = config.theta; this.thetaSpeed = config.thetaSpeed; this.lightColor = ...

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