CSCI 201 Lab 6 -- Making faces with EzWindows
In this lab you'll use the EzWindows interface to
make a face.
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. If you
need a review, go back to Lab 4
now.
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
First note the use of the two routines ApiMain and
ApiEnd. You saw them both before, but we didn't talk much about
them.
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
- Position NosePos(6.0f, 9.0f) ;
We didn't need Positions in the
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, this saves typing.
Rectangles
You met the RectangleShape object in the stonehenge lab.
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
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:
- 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 (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:
- 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. To provide some inspiration, here are some of the faces that students have created in the
past.
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
year.
Advanced Graphics
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.
Return to CSCI 201 page
Return to the UNCA Computer Science home page