CS 3 (Spring 2023) Project 02: Gravity

In this project, you will continue your physics engine by adding gravity that acts on multiple polygons!

Code Correctness

Goals and Deliverables

The main deliverable this week is a “gravity” demo which should look something like the following:

Conceptually, this demo is a strict generalization of the “bounce” demo from last week. Instead of one star, we’ll have \(n\). Instead of one color, we’ll switch through many.

We expect your demo to contain (at least) the following:

You will need slightly better abstractions (in particular, you will need some kind of resizing for your list) than you did last week, and we expect you to spend a significant amount of the project time on improving them. Your bounce demo from the previous week should still compile and run correctly despite any changes you might make. This means that gravity should be a separate demo. This week, we will also ask you to write some tests for the list(s) you create. You are allowed to edit any and all files we have provided to you.

If you find yourself spending very little time on this project other than writing the demo, something about your architecture probably needs to be modified.

All coding must be done in (at least) pairs via pair programming this week. Nobody is allowed to code without another group member present. This is because the design decisions are the major goal this week, and you must justify them amongst yourselves before actually coding.


As the project gets bigger, the architecture of the individual pieces and how they fit together becomes more and more important. Since this is such an important focus of this week, we will break up your grade into four pieces (rather than the usual three):

Here’s a bit more detail about the two new categories:

Project Architecture

We believe the current size of the project is a good size for you to experiment a little bit; so, this week, we will provide basically no guidance of how to actually break up your code. (However, we will discuss this in great detail with you at the code review.) Next week, we will require your architecture to fit with where we’re eventually going (generalized forces acting on bodies, testing for collisions, etc.). You are encouraged to discuss your design at office hours. You can (and should) modify the Makefile to include your new targets. If you do not have at least one new module, you are doing something wrong.


Since this is the first week we are actually requiring you to write your own tests, we will grade these very leniently. At the very least, you must copy our tests from the previous week and modify them to fit your new architecture to get these points. Note this week there are no tests to pass on gitlab.