Homework 11: Bouncy Balls

Assigned
Tuesday April 19
Due
11 p.m. Monday April 25
Summary
In this assignment, you will (1) build a 2D vector class with operator overloading, (2) construct a simulation of bouncing balls using Newtonian motion, and (3) propose a game based on this simulation or our exercises in class.
Collaboration
For this assignment, you will work with a partner of your choice. You are welcome to make arrangements before class, and I will also leave time in class.
Submission
Online turnin form, Wrapper
Warning
So that this exercise is a learning assignment for everyone, I may spend class time publicly critiquing your work.

Assignment

  1. In this exercise we will create a vector class. Start with this class definition skeleton (vector.py). Fill in the methods so that the class passes all of the tests at the bottom of the skeleton. When all the tests pass, submit the file vector.py through the online turnin form.

    Import vector.py into a new processing sketch and continue on to the next exercise.

  2. In this exercise we will create a Processing sketch that lets the user place bouncing balls on the canvas. Read about simulated Newtonian motion to help you write your program. Write a sketch that:

    1. allows the user to click on the canvas to create a new ball there with random x and y velocities (each between -10 and 10).

    2. uses gravity to attract the balls towards the bottom boundary of the canvas.

    3. lets the balls bounce off of the walls at the edges of the canvas.

    4. represents the balls using a Ball class. The Ball initializer method should accept at least the initial position vector and initial velocity vector.

      In addition, the Ball class should have an update() method that updates the position of the ball according to the velocity and acceleration. And, a draw() method that draws the ball.

      Finally, the vector class defined in vector.py should be used to represent the position, velocity, and acceleration as vectors. Add the vector.py file that you created in the previous exercise to your processing sketch and put from vector import * at the top of your processing sketch.

    5. uses a list to hold all of the ball objects.

    6. includes some kind of Above & Beyond element. Note: It's okay if this replaces some of the earlier requirements. For example, the slingshot effect that I built replaces the original mouse click behavior specified in point (a).

    Submit the .pyde file for your sketch using the the online turnin form. If you have added further methods to the vector class, please also submit your revised vector.py file.

  3. Submit a proposal for a game in a separate file named proposal.txt. After receiving feedback from me about the feasibility of the idea, you and your current partner will program the game in Processing for the final homework assignment.

Submitting your work

You should have submitted three files using the online turnin form: vector.py, bouncy_balls.pyde (or something similar), and proposal.txt. Individually complete the assignment Wrapper on Google Forms.


General requirements

These requirements apply to this assignment and all future assignments.
  1. Make sure that you save your programs in the correctly named files.
  2. Follow the style guidelines given in Chapter 6 of the textbook:
    1. use 4 spaces (instead of tabs) for indentation;
    2. limit line length to 78 characters;
    3. when naming identifiers, use lowercase_with_underscores for functions and variables;
    4. place imports at the top of the file;
    5. keep function definitions together;
    6. use docstrings to document functions;
    7. use two blank lines to separate function definitions from each other;
    8. keep top level statements, including function calls, together at the bottom of the program.
  3. Make sure that you are following the academic honesty policies regarding programs.
    1. If you work with a partner, make sure both partners contribute to all parts of the assignment so it is a learning experience for both of you.
    2. You can probably find versions of the required programs online. Don't be tempted to plagiarize! You must solve the problems yourselves to learn from the assignment. If you get stuck, use the health & well-being policy to obtain an extension and come to office hours for help.
  4. In your comments at the top, make sure you:
    1. name all authors;
    2. acknowledge any help or outside sources, in accordance with the academic honesty policy;
    3. describe your Above & Beyond components, if any;
    4. describe any known bugs in the program.

Janet Davis (davisj@whitman.edu)

Created April 3, 2016
Last revisedApril 19, 2016, 09:31:28 AM PDT

Acknowledgements: This assignment is adapted from one developed by Karen Reid and disseminated through SIGCSE Nifty Assignments.

CC-BY-NC-SAThis work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.