CSE 142 Homework 4

Hall of Fame

New! See the Homework 4 Hall of Fame

The Lakeside



introduction

In this homework, you will modify and extend a program that displays a simple animation of a lakeside scenery, and you will have an opportunity to exercise your creativity and imagination.

key concepts

In addition to concepts with which you should be comfortable by this point, e.g. variables, conditionals, loops, functions, this homework highlights the following concepts:

In addition to the above key concepts, this homework will give you experience with two common necessities of real-world programming:

task description

The starter program for this assignment is available both as a sample executable and as a C source file.  Unlike past assignments, this time the starter code is the complete sample executable program.  Some of this writeup won't make much sense until you've spent some time experimenting with the sample program and looking at the source code.

The starter program displays a country view with some mountains, a flower, a butterfly, and other things.  There is also a menu in the top corner with three entries, only one of which does anything (you can click on "change colors" to change the color of the flower).  The lone butterfly hovers around a small part of the screen.

Your job is to extend the program so it does something interesting.  The assignment is open-ended - use your imagination.  The minimum requirement is that the program have several things moving around the screen (swarms of butterflies or a constellation of stars or dancing plants, for example), and you must use arrays to keep track of the location and any other properties (colors, size, whatever you choose) of the moving things.  There are also some menu buttons that currently don't do anything.  You could implement them to do what they say they do, or change, add, or delete menu buttons to give the user additional abilities. Beyond that, you should use your imagination show your creativity.

To get started, you'll need to study the starter program, see how it works, and figure out how to add to it.  Develop your program incrementally.  That is, make a small change, get it to work, then add something else, get that to work, and so on.  You should turn in your program when you have the basic part working, then add to it and turn in later versions closer to the assignment deadline.  It is better to have a smaller program meets the requirements and works instead of a grandiose program that isn't working when the deadline arrives.

details

Reading the starter program

To get started, run the program, look at the starter C file hw4_orig.c, and figure out what it does (There's an important note in using GP142 below about compiling the program.)

static call graph

Once you have a clear understanding of what the program does, you should study the code to find out how it accomplishes this. For example, make sure to understand how clicking a button actually changes the color of the flower, tracing control flow carefully.

To help guide yourself the rest of your work on this homework, make a static call graph showing all the functions called in hw4_orig.c, starting, of course, with main. Your static call graph should include GP142 functions that are called directly by functions in hw4_orig.c, but should not include other functions inside GP142 that are not used by the starter program. Making this graph will aid you in the assignment by giving yourself the overall program structure, so it is the first thing you want to start with.

Hand in a copy of your static call graph in quiz section on Thursday, May 11th.

Remember from lecture that a static call graph shows the calling relationship between functions in the program - which function(s) call which other function(s).  In particular,

implementation

As provided, the hw4_orig.c program displays some blinking stars, a tree/flower, a moon moving across the screen, and a butterfly. A panel of buttons is visible in the top-left corner of the screen. The "Change Colors" button work to modify the color of one flower, but the rest of the buttons do nothing.

Study the event loop in the main program.  Locate the place where menu commands are handled.  One thing you might want to do would be to get the other buttons to do something interesting.  Of course, you could also get rid of the existing buttons and do something different.

Next study the random movement of the butterfly and see how that works.  Its horizontal and vertical coordinates are updated periodically by adding a random amount (provided by the rand() function) to the previous coordinates, then the scene is redrawn.

You need to modify the program so there are several things moving around the screen - either butterflies, stars, or other objects.  The number of things on the screen should be adjustable, and you should use arrays to keep track of the information about the moving objects. Your program should have a #define constant for the maximum number of objects that can be moving around the screen simultaneously. You will not receive full credit for a program with, for example, three sets of variables (as opposed to a set of arrays) to keep track of three (and only three) butterflies.

Exactly how you modify the animation is up to you, provided you satisfy the specifications above. The most imaginative programs will be nominated for a Hall of Fame, and, time permitting, a few of them will be demonstrated in lecture.  (Try to come up with something that will amaze your TA and have him/her running down the hall to show it to everyone else on the floor.)  A small amount of extra credit will be awarded for programs that go beyond the basic requirements.  How much will be determined by what you do.

Here are some possibilities to get your imagination working, but you do not have to choose from this list if you have ideas of your own:

important reminders

As always, remember to use good style:

The random number generator is used in the sample executable and skeleton program, and an #include the standard library header, stdlib.h is provided to make this possible. Feel free to use random numbers in your code.

You might notice that there are hints in square brackets in the comments included in hw4_orig.c. Some (but not necessarily all) of the places that might require modification are marked with these hint comments.

using GP142

learning about GP142

You will find the GP142 User's Guide (also linked on the main Homework page) useful as a reference as you read and write graphics code in this homework.

special settings for building GP142 programs

If you are using Windows, we strongly advise that you compile and modify the program ONLY via the .dsw file that will be supplied in the self-extracting archive. Here's why: GP142 programs differ from previous projects in some important ways. First, they have multiple .c files (gp142.c in addition to your own). Second, they use a special .h file that must be available to the compiler. Third, they are built as "Windows Applications" rather than "Console Applications." All of this means that you cannot create a "default project workspace" to compile and run your program in. If you double-click on the .dsw file we give you (.dsp for users of some older versions of MSVC), all of these special settings are taken care of.

If you really need to know how to create your own project, look at the MSVC tips page, which is also linked on the course home page.

We recommend that you work on a Windows PC to work on this homework, but the GP142 User's Guide page also includes information for Macintosh and X Windows (UNIX) users.

submission guidelines

As always, be sure to read the homework submission guidelines, linked on the course home page in the Announcements section. You will have to submit your work (1) via the web using the page linked below and (2) on paper (a printout of the web turn-in receipt page).

files

announcements

If any clarifications or changes need to be made for this homework, they will be posted to the cse142-announce email list and linked here.

Return to main Homework page...
Last modified: Wed May 3 11:54:39 PST 2000

Save paper: Read documents on the web when you can and, if you print, print two-sided. Remember to reuse or recycle this paper when you're done.