< Back

Assignment 2

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 assignment2
$ cd assignment2


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

Using the Turtle module, your program should draw a series of 3 concentric circles on the right hand side of the screen. These circles will represent the target that your ballistic simulation will be aiming for.

Your program is going to launch projectiles from the lower left corner of the window. To accomplish this, your program should prompt the user to enter both an initial x component of velocity, and an initial y component of velocity.

Given this information, your program should draw some fixed number of lines segments that will approximate the ballistic trajectory of the launched projectile. 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 can do this by simply subtracing the acceleration due to gravity (9.81 m/s2) from the y component of velocity, and adding the acceleration due to wind (Which we will assume for now is 1 m/s2).

Keep in mind that your program does not need to stop when the user hits the target, nor does your program need to stop when the turtle leaves the screen. You simply need to draw some fixed number of line segments to represent the projectile path.


"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. Continued Play: Right now, your program stops after the first projectile. For this hacker prompt, you should restructure your program such that, after the first projectile, it asks again for another set of x and y velocities. This should continue for some fixed number of steps.

  2. 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.

  3. 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.


Grading

The assignment will be graded on the following requirements according to the course’s programming assignment rubric.

Functionality (75%): A functional program will:

  • draw 3 concentric circles,
  • align these circles in the lower right hand corner of the screen,
  • ask the user for 2 integer input values for x and y velocity,
  • draw a fixed number of line segments representing the ballistic trajectory of the projectile,
  • start the path of the projectile from the lower left hand corner of the screen, and
  • account for gravitational and wind forces in the computation of the ballistic trajectory.

Style (25%): A program with good style will:

  • include a header comment signifying the authors of the file,
  • avoid magic numbers (literal primitive numbers),
  • use meaningful names for variables,
  • have statements that are small (80 characters or less including leading space) and do one thing, and
  • have spaces after commas in argument lists and spaces on both sides of binary operators (=, +, -, *, etc.).

Creative: Drawing

Computers can be powerful tools for artists. Their ability to represent curves and lines precisely make them a useful tool for graphic designers. In this assignment you will use the Turtle module as a computer aided design tool.

Details

Create a Python program that uses the turtle module to draw a picture. The picture can be anything you want, but must do the following:

  • Use a for loop that iterates multiple times.
  • Use the input function to get user input that changes the drawing.
  • Use the begin_fill and end_fill to draw something filled.

Extra

Astounding drawings will receive extra credit. I will be the arbiter of whether a drawing is astounding.

Grading

The assignment will be graded on the following requirements according to the course’s programming assignment rubric.

Effort (40%): Here are some examples of drawings with average effort:

Turtle Graphics Yin Yang Symbol Turtle Graphics Green Lantern Symbol

Functionality (35%): A functional program will:

  • use a loop.
  • use user input.
  • draw something filled.

Style (25%): A program with good style will:

  • include a header comment signifying the authors of the file,
  • avoid magic numbers (literal primitive numbers),
  • use meaningful names for variables,
  • have statements that are small (80 characters or less including leading space) and do one thing, and
  • have spaces after commas in argument lists and spaces on both sides of binary operators (=, +, -, *, etc.).

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 2 link. Both partners must submit through cseval!