HTML and CSS Reference
In drawScreen() , we simply add xunits and yunits to ball.x and ball.y . We don't check
to see whether moves has been exhausted because we are not moving to a particular
point—we are simply moving along the vector, seemingly forever. In the next section,
we will explore what we can do if we want the moving object to change direction when
it hits something such as a wall:
ball.x += xunits;
ball.y += yunits;
Figure 5-3 shows what Example 5-3 looks like when it is executed in a web browser.
Recall that the points are drawn for illustration only.
Figure 5-3. Moving an object on a vector
Example 5-3 gives the full code listing.