EXERCISES FOR WEEK 4
week4-1

Write a function which accomplishes the task you just completed in the last exercise of week 3 (week3-8). That is, write a function

Tween

which takes two points as input, A and B, a real value for t, and then returns the point on the line through A and B for that particular value of t. Check your function by passing in points A and B as defined in exercise week3-10 and the values for t.

Note:  We want to be able to easily use this function for 3D points as well.

week4-2

In exercise 3-8, we end up plotting 6 points (including the two endpoints) on the line and increment between successive values for t is 0.2. In general, if you want to plot numframes points on the line segment from point A to point B, including the two endpoints, what is the value for increment that you would use?

 

week4-3

Suppose you have an array of points, StartArray, which contains all the vertices of the figure your animation should start with, and a second array of points, DestinationArray, which contains all the vertices of the figure which is the destination of your animation. Assume there are numpoints points in each array. Write a function, FillTween, which takes as input:

  • the two arrays of points
  • the value for numpoints (the number of points in each array)
  • the value for t

and returns an array of points with numpoints points in it; each point calculated using corresponding points of StartArray and DestinationArray and calling the function Tween.

week4-4

Now write a function, DrawSequence, which takes as input:

  • the array of points to start with
  • the array of points for the destination
  • the number of frames you want from start to destination, inclusive (numframes)

and does the following:

for every frame to be drawn:

clears the screen;
calculates the value for t;
uses FillTween to fill a new array of points;
draws the figure, using the array of points and whatever instructions you have for how to connect the points (should be a function call);
swaps the buffers;