For the mechanics and engineers out there, this one's for you. In this recipe, we'll create a system of interconnected rotating gears.
Follow these steps to animate a system of interconnected gears:
Link to the
Animation
class:<head> <script src="animation.js"> </script>
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 = config.lightColor; this.darkColor = config.darkColor; this.clockwise = config.clockwise; this.midRadius = config.outerRadius - 10; }
Define the
draw
method...