Adding Animation
Animation lends itself to test-driven development just as much as any other feature. In this chapter, we’ll animate the Logo turtle movement as the user inputs commands.
There are two types of animation in Spec Logo:
- First, when the turtle moves forward. For example, when the user enters
forward 100
as an instruction, the turtle should move 100 units along, at a fixed speed. As it moves, it will draw a line behind it. - Second, when the turtle rotates. For example, if the user types
rotate 90
, then the turtle should rotate slowly until it has made a quarter turn.
Much of this chapter is about test-driving the window.requestAnimationFrame
function. This is the browser API that allows us to animate visual elements on the screen, such as the position of the turtle or the length of a line. The mechanics of this function are explained in the third section of this chapter, Animating with requestAnimationFrame.
The importance of manual testing...