Wednesday, March 18, 2009

Canvas Exercise

File:Unit circle.svg

For today's exercise you will write a simple canvas application: an analog timer. You will email me what you have done by the end of class. What you need to do is:

  1. Draw a circle.
  2. Draw a line from the center of that circle to the 12'clock position.
  3. Implement a simple animation which erases the whole thing then re-draws it every second, but with the line moving to the next position. That is, make the line move like the second-hand in a clock.

The third point might require some basic geometry. Remember that if t is the angle (in radians) then the point (x,y) in the unit circle (centered at 0,0) that is an angle t from (1,0) is given by: x = cos(t) and y = sin(t), as illustrated by the diagram you see here.

No comments:

Post a Comment