How it Works: Drawing the Trajectory
In this lesson, we will understand the implementation of the previous exercise. Let's begin!
We'll cover the following...
How it works
The trajectory variable, var trajectory = [];
, you added in step 1, represents an empty array.
In step 2, you saved the current ball position with the following code:
Press + to interact
trajectory.push({ x: ballX, y: ballY })
This code, which is the invocation of push()
, added a new object to the trajectory array. This object is created with JavaScript’s object notation as a tuple of two coordinates, ...