CSCI 201 Lab 5 -- Making faces with EzWindows

In this lab you'll use the EzWindows interface to make a face.

As you must recall, in Lab 4 it was stated that future labs will never contain detailed information about setting up a Visual C++ project using EzWindows. If you need a review, go back to Lab 4 now.

Getting stared

Create a project of type Win32 Application (not type Win32 Console Application) in C:/FILES called Face. Add the EzWindows library to the project and modify the compiler options to use the EzWindows include directory.

Add a new C++ Source called face.cpp to your project. Use cut-and-paste to copy an initial version of face.cpp into your program. Build and run your program. You should see a rather abstract face with only a nose and mouth.

Program elements

This program uses constructs described briefly in Chapter 3 and fully in Appendix E of the CSCI 201 textbook.

The beginning and the end

First note the use of the two routines ApiMain and ApiEnd. You saw them both last week. ApiMain is called when your application begins execution. Its sibling routine, ApiEnd, is called just before your application is terminated. ApiMain replaces main when you are using the EzWindows library. You should never change ApiEnd in today's lab.

Positions

This week we are using the EzWindows Position class to represent points within the window. Here's one instance of constructing a position called NosePos

We didn't need Positions on last week's stonehenge lab because we were only displaying rectangles. However, this week we're going to suggest you display ellipses and triangles and these EzWindows objects do require Positions.

You'll find Positions to be useful when you are defining several objects centered on the same point, such as the pupil and iris of an eye. You describe the point once as a Position and then use the Position several times. Saves typing.

Rectangles

You met the RectangleShape object last week. This week we're going to suggest that you use Positions when you define RectangleShapes as in: Remember that the last two parameters to the RectangleShape constructor are the width and height of the rectangle.

Once you've defined a shape, you use the Draw method to display it in the window.

Ellipses

The ellipse is the first of this week's two new shapes. The definitions for rectangles and ellipses are very similar: Again, the last two arguments are the width and height of the ellipse. In this case, the two arguments are the same so we actually get a circle.

Remember to Draw your ellipse after you've defined it.

Triangle

This week's second new shape is a triangle. EzWindows triangles are a tad boring. They are all equilateral triangles which point upwards. An example definition follows: Note that the TriangleShape constructor only has one size argument. It is the last argument and gives the length of a side of the triangle (remember, it's a equilateral triangle so all sides have the same length).

Lab Checkoff

This lab has more indefinite goals than the previous ones. However, it has two definite rules:

  1. You must work with a partner.
  2. You can not leave for at least one hour.

Your job is to improve the face. At the minimum you must add hair and eyes. To provide some inspiration, here are some of the faces that students created last semester. If you finish that early, you should try something else like a beauty mark, eyebrows, or even facial hair. By the way, the monocle is a challenge. You have to draw two ellipses, an initial ellipse of black to be the rim of the monocle and then a smaller ellipse of yellow to repaint the background inside the monocle.

What to turn in

If you are proud of your efforts, provide your lab instructor with a floppy containing your C++ source file. We'd like to add your creation to the gallery of faces started last semester.

What's in store for the future

Download the EzWindows executable ultimate.exe and run it. Notice that the teeth appear three seconds after the face is first displayed. Also, try pressing on the face with your mouse. This draws beauty marks.

Extra Credit

If you go through this exercise at warp speed, you might consider using the RenderText and RenderPolygon functions (also called methods) described on pages 837 and 838 of the textbook. Using these methods, you should add labels and downward-pointing teeth to your face.


Return to CSCI 201 page
CSCI logo Return to the UNCA Computer Science home page