CSCI 201 Lab 4 -- Making faces with EzWindows
In this lab you'll use the EzWindows interface to
make a face.
As you must recall, in Lab 3
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 3 now.
Getting stared
Create a project of type Win32 Application
(not type Win32 Console Application this time)
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 ApiMain last week.
It is called when your application begins execution.
Its sibling routine, ApiEnd, is called just
before your application is terminated.
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
- Position NosePos(6.0f, 9.0f) ;
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:
- RectangleShape Nose(MyWin, NosePos, Red, 2.0f, 3.0f) ;
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 paint it
to the window.
Ellipses
The ellipse is the first of this week's two new shapes.
The definitions for rectangles and ellipses are very similar:
- EllipseShape LIris (MyWin, LEyePos, Blue, 0.8f, 0.8f) ;
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:
- TriangleShape Nose(MyWin, NosePos, Red, 2.0f) ;
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.
Lab Checkoff
This lab has more indefinite goals than the previous ones.
However, it has two definite rules:
- You must work with a partner.
- 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.
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.
If you go through this exercise at warp speed, you
might consider using the RenderText
and RenderPolygon methods described on
pages 837 and 838 of the textbook.
These will allow you to add
labels and downward-pointing teeth
to your face.
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 make a gallery of some of
the better faces.
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.
What can go wrong?
Make absolutely sure that you have terminated
execution of your program before you try to modify and rebuild it.
Return to CSCI 201 page
Return to the UNCA Computer Science home page