4.2.2 Exercises

Exercise
The methods Sin() en Cos() allow you to retrieve the sine and cosine from any value. This is most fun when that value is the current time. The result over time is a value which moves smoothly between -1 and 1.
 
float x = Sin(Time.curTime()); 
float y = Cos(Time.curTime());  

  1. The code above illustrates how to use the sine and cosine with the current time. Create an application which shows a line, starting from the middle of the screen towards the current value of sine and cosine for the x and y value of the ending.
  2. Change the width of the line.
  3. Make the line move at double speed.
  4. Decrease the length of the line.
  5. (This will be a bit harder) Try to create an analog watch.

Exercise
Take a look at Esenthel Engine Math Shapes Edge. Examine the method lerp(float s). This function needs an argument between zero and one, and return a position on the line.

  1. Define an Edge2 and a float with value zero.
  2. In the init function, assign a start and end position to your line.
  3. In the update function you increase the float with Time.d(). When the float value is larger than 1, is should be assigned 0.
  4. Draw the line in black with a width of 0.05. Construct a Vec2 with the result of lerp(). The argument of the method should be your float. Draw this point in red, also with a width of 0.05.

Exercise
Draw a triangle on the screen.