< Back

Assignment 3

This is a pair assignment. You should create a directory called assignment2 in cs120/assignments for this assignment. All code written for this assignment should be stored in that directory.

$ cd ~/cs120/assignments
$ mkdir assignment3
$ cd assignment3


Projectile Motion

The first electronic programmable computer, ENIAC, was created for performing ballistic calculations for the United States Army. ENIAC was the size of a school bus and weighed 30 tons. A lot has changed over the years, to the point where pocket sized computers (Cell Phones) now have more computational power than the ENIAC. For this assignment, you will use your modern day computer and the turtle module to perform similar calculations.


Details

Create a function called draw_arc(initial_x, initial_y, velocity_x, velocity_y, gravity, wind). You can assume all parameters to this function will be floating point values. initial_x and initial_y are the initial locations of some projectile, and are relative to the origin on the turtle window. velocity_x and velocity_y are the x and y components of the initial velocity of the projectile. gravity is the force that is pulling down upon the projectile and only affects the vertical speed of the projectile. wind is the force that affecting the horizontal speed of the projectile.

This function should draw some fixed number of line segments that will approximate the ballistic trajectory of the projectile launched from the specified starting location with the specified starting velocity. Each line segment can be calculated by using the projectile's current velocity to compute the new location of the projectile (assuming the projectile is traveling in a straight line). Once you compute the new position, you then need to compute the new velocities in the x and y directions. You do this by subtracting gravity from the y velocity, and adding wind to the x velocity.

Write a function to draw a target on the right side of the turtle window. This is simply 3 concentric circles. Your program will then use an input statement to get the starting X location and the projectile's speed. Using a for loop and the function defined above, try all of the possible angles (from 90° to 0°, using increments of 5°). You will have to use the trigonometric functions to convert the input speed and chosen angle into x and y velocity components for your draw_projectile function.

You should use the turtle.write function to label your projectile paths with the angle that drew the line. Someone using your program should be able to visually see which angles produced a path that traveled through the target.


"Hacker" Prompt

Each week, additional exercises related to the assignment will be provided at the end. These exercises are typically more challenging than the regular assignment. Bonus points will be provided to students who complete any of the "Hacker" level assignments.

  1. Air Resistance: The code above assumes the projectiles are fired in a vacuum. While space combat seems fun, it's not very useful for Earth based projectiles. Add air resistance to the simulation. Air resistance is an acceleration that is always opposite the direction of the velocity. Thus the x and y components of the air resistance must be recalculated every time velocity is updated.

  2. The Monkey and the Hunter: The monkey and the unter is a classic physics question. If a hunter aims a dart gun directly at a monkey hanging on a branch and the monkey lets go at the same instant the hunter fires, will the monkey be hit? Simulate this by creating two projectiles. One projectile, the monkey, with an initial velocity of 0 in both the x and y direction. The other projectile, the dart, with an initial velocity directly toward the initial location of the monkey.

  3. Easier Labels: Now that you know if statements, you can make figuring out which shot landed in the target easier. If you detect that one of the discrete points on the path results in a target hit, change the color of the text used to label the shot to some easy to notice color.


Creative: Game

Your average cell phone now has vastly more programming power than the video game consoles of the seventies and earlie eighties, but the games made for those consoles are still fun to play. In this assignment you will create a game in the style of these retro video games. If you need some inspiration take a look at some of the games on The Console Living Room web site.

Details

Create a Python program that uses the graphics.py module to recreate a retro video game. The game can be anything you want, but must do the following:

  1. Use keyboard input from the user.
  2. Have more than one image.
  3. Have at least one image that moves.
  4. Display text in the window when the player wins or loses.
  5. Be impressive.

Note that we don't yet know how to close the window when the user wins or loses. So the game should run for a fixed amount of time and then end.

Extra

Superb games will receive extra credit. I will be the arbiter of whether a game is superb .


Your program should include the traditional header, use appropriate variable names, and nicely label all values printed to the terminal. Submission are to be done through inquire.roanoke.edu through the Assignment 1 link. Both partners must submit through inquire!