Lab 3 - Intro to Computer Graphics


The purpose of this lab is to learn how to write a simple graphics program.

Output Requirements

Write a graphics program that draws a regular polygon in the graphics window.

Input Requirements

The user enters the number of sides, the center point coordinates, and the radius of the polygon on the console window.

Process Requirements

Draw the regular polygon.

Miscellaneous Requirements

The graphics window should be 201 pixels wide and 201 pixels high. The title of the graphics window should be "Polygon".

The actual drawing of the polygon should be done using a function named "drawPolygon". Here is the prototype of this function:

// drawPolygon
// This function draws a regular n-sided polygon
// using the specified color. It will have the
// specified (circumscribed) radius and be
// centered on the specified point.
// In parameters: color, centerX, centerY,
//                radius, n
void drawPolygon(int color,
                 int centerX, int centerY,
                 int radius, int n)

This function does not permanently change the current color. That is, in the invoking function, the current color will be the same after this function terminates as it was before this function was invoked (get the current color, save it, change the color to the specified color, draw the polygon, change the color back to the value you saved earlier).

Sample Run

A sample run showing both the console window and the resulting graphics window is illustrated below:

Sample Run 

Project Files

You will have to create your own project file. It should be named "Lab03". Download this Lab03.cpp file and add it to your project. I've done much of the work for you. All that is left to do is to initialize the graphics window in main and implement the drawPolygon function.

File Submission

Email me your Lab04 project file (PARJ) and program file (cpp).