Array Types

The Sun, the Earth, the Moon and one Satellite

The purpose of this exercise is to animate planets on the screen, one planet turning around the other.


Expected result

Question 1

Create an enumeration type for various celestial bodies (Sun, Earth, Moon, and Satellite) and an enumeration for various parameters (X, Y, Radius, Speed, Distance, and Angle).

Create two array types, one array containing the colors of each body, and one two-dimensional array for the values of the parameters to store.

Declare one variable of each array type. Initialize the values of the parameters array with the following semantics:

  • Speed: angle step (in radians) that has to be added to the star angle at each iteration. Use values between 0.01 and 0.1 radians per iteration for this exercise.

  • Distance: distance from the body to the previous one (not used by the Sun star). This distance is in pixels; use a value between 5 and 50 pixels.

  • Angle: current angle between the body and the previous body (not used by the Sun star). This angle may be initialized at 0.

  • X and Y represent the position of the object and can be initialized at 0.

Initialize the values of the array variables containing the color of each object.

Question 2

Create an infinite loop that moves the four bodies by one predefined step on every iteration. Each object is supposed to rotate around the previous one in the Bodies_Enum enumeration.

Use a delay until statement in the loop to control the iteration period.

Refine the values chosen in the previous question in order to have a smooth movement.