Programming Course for Beginners - ZedLX

The Easiest Online Computer Programming Course, for Free

The type vector2D [7/11]

This program illustrates how to create motion by using vectors.
[Run the program]

The point position represents the balls's current position. The initial position is (400, 500) .

The vector velocity represents the balls's speed and direction. The velocity is constant and equal to (2, -3) .

On each display frame, the position of the ball is moved by the vector of motion velocity. This rule is implemented in the penultimate statement of the main loop:
position = position.add(velocity);

Exercise:

Change the initial value of vector velocity. Try various positive and negative values for the vector's coordinate components x and y.

Loading...