In Circles Programming Assignment

September 1997 - Fell

Overview
In this project you will use for and while loops to produce circular motion. There are two parts to the assignment. In the first part you will roll a ball around a circular track. In the second part you will produce a colored spiral, roll a ball along a spiral path, then slowly erase the original spiral. Goals

Getting Started Your Tasks
Add your name, ID number, and the date to the comment block at the top of the program.

Writing the Code: You must add two functions:

	void CircleTrack(void);
	void Spiral(void);
(1) Add the function prototypes below the prototype for main.
(2) Add dummy implementations (functions with empty bodies) of these functions after implementation of main. The dummy implementation for CircleTrack is shown here:
	void CircleTrack(void){
	}
(3) Add calls to your functions in the main program.

Run your program to make sure it compiles.

The Circular Track

Your program should be at least as good as the sample. You may change the colors and add frills if you wish.

(4) Draw the track
In the sample, the center of the track is 150 pixels from the center of the drawing window and the ball has radius 13. You can make a track like the one in the sample by calling:

	PaintRect		to color the whole drawing window
	EraseCircle		to clear everything inside the outer edge of the track 
	PaintCircle		to fill in everything inside the track
(5) Place the ball
Draw the ball in its starting position and write a message asking the user to press the mouse button to start the ball rolling. Then call
	AwaitClick(); 
Nothing will happen until the mouse button is pressed and released.

(6) Roll the ball around the track.

You need some trigonometry to do this task. In the demo application, the angle theta that the ball has traveled around the circle starts at 0” and increases in 1” increments. The following picture should remind you of the conversion from polar coordinates to x, y coordinates:

The formulas:

x = R*cos(angle), y = R*sin(angle)

where R is the track radius, assume that angle is measured in radians. Our angle is measured in degrees so you must first do the conversion:

	angle = theta*2*pi/360;		// pi is an already defined constant
Also, remember that the center of the track is at (200, 200) so you must add 200 to x and y. Use PaintCircle to place the ball and EraseCircle to remove it before you draw the next ball.

Use Delay(1) to slow down the ball so it moves at a reasonable speed. Insert the delay after you draw the ball and before you erase it. This makes a ball present on the screen most of the time and fools us into believing itÕs always there.

(7) How long should the loop run?

To let the ball continue moving until the mouse button is pressed, use a while loop:

	while (not Button()){
	} 

The Spiral

Try to make your program at least as good as the sample. You may change the colors and add frills if you wish.

(8) First draw the spiral in black.
A good range for theta is: 0 <= theta < 1000. Use the same conversions from polar to x, y coordinates as described above. This time, however, the distance r of the ball from the center of the window changes with theta. The formula:

		r = theta/5
makes r = 200 when theta = 1000 and thatÕs just the right distance to place the ball at the edge of the window.

(9) Now make the color vary with theta.
Call SetForeColor(red, green, blue) before the PaintCircle call. Let the color values red, green, and blue vary with theta but make sure they stay in the range 0 to 255.

(10) Erase the spiral by using EraseCircle and running the loop from theta = 1000 to theta = 0.

(11) Finally, add the little ball that runs around the spiral. Put this code before the code that erases the spiral.

(12) In the solution program, a click on the mouse will end the spiral. This is accomplished by adding the call

	if (Button()) return;
to each of the three loops. If the button is pressed, the control returns to the main program, after the call to Spiral().

Due Date: Turn in at your Lab class, Tuesday or Wednesday, October 7 or 8.

Turn in a print-out of your code and a diskette with your project (.µ), your source code (.cp), and a working application program.


Last Updated: September 28, 1997 12:46 am by

Harriet Fell
College of Computer Science, Northeastern University
360 Huntington Avenue #161CN,
Boston, MA 02115
Internet: fell@ccs.neu.edu
Phone: (617) 373-2198 / Fax: (617) 373-5121
The URL for this document is: http://www.ccs.neu.edu/home/fell/COM1100/HW/InCircles.html