CS010 Introduction to Computer Science I
Term Project
Deliverable One


Swarm and Flocking Behavior:
Basic Infrastructure
(last updated 4/1/2005)

For the first deliverable, you will extend the solution to problem 4 from the second exam.  The main goals at this stage are to create, update, and animate a swarm of critters.  As a graphical application, you will be using many of the techniques you have encountered in earlier exercises.  Make sure you create global constants for things such as the width and height of your canvas so that they can be changed easily later.

We will use a list of critters as our representation of a swarm; you should include this in your file as an appropriate data definition.  Then you will write functions to display-critter, clear-critter, update-critter based on speed and heading, and finally, draw-and-clear-swarm.  Together with your move-all-critters from the exam, you should be able to animate a swarm; your animate-swarm function should consume a swarm and a natural number as arguments, and then draw, clear, update and so-on as many times as specified by the given number.  You will probably want at least one utility, for example, a function to create a semi-random swarm.  However, you may encounter other needs and you should create helper functions as appropriate.  Organize your functions in your file in an orderly fashion.

For now, the data definition of a critter is the same as was used on the test.  A critter is a structure: (make-critter p h s), where p is a posn, h is a number representing a heading in radians, and s is a number representing the number of pixels the critter will move forward on a given time-slice (single update).  Use the structure definition: (define-struct critter (location heading speed)).  To display a single critter, draw a dot at its location and a line about 5 pixels long in the direction of its heading.

You should use the following standard for drawing and orientation.  When talking about the standard compass headings, N, S, E & W, the directions should correspond to up, down, right and left respectively.  The critter heading, given in radians, starts at 0 heading East, and increases positively clockwise (negatively counter-clockwise).

There is one twist to your update-critter function.  When a critter moves off the canvas in any direction, it should re-appear on the opposite side.  For example, if my canvas is 100 x 100, and I have a critter at location (97,50) moving southwest five units per time-step, it should re-appear on the left side of the canvas at location (2,55).  You will find the DrScheme function, modulo, helpful in this.

To grade this deliverable, I will review your code (including contracts, purpose statements, indentation, etc.), and then call your animate-swarm function using a swarm of my own.   Therefore, it is important that you follow the data definitions carefully.