88. Slingshot

The previous simulations used simple rules to produce complex behavior. Even the Sharks and Fish simulation, which uses a lot of parameters, doesn't really model the real world accurately.

To solve the current problem, you need to use a relatively realistic model for projectile motion. Create a slingshot program similar to the one shown in the following screenshot that lets the user fire projectiles:

The user should be able to click and drag to pull the shot back at most a certain distance from the slingshot. In the screenshot, the faint dotted circle indicates the farthest that the user can pull the shot.

When the user releases the mouse button, the program should launch the projectile in the direction given by the rubber bands with an initial speed that depends on how far the shot has been pulled back. The program should then move the projectile appropriately until it leaves the form's sides or hits the ground.

If you don't know how to model projectile motion, you can read the first section of the solution later in this chapter for a brief overview. If you want more information, see http://en.wikipedia.org/wiki/Projectile_motion or www2.hawaii.edu/~takebaya/lessons/lesson3.pdf, or search the web.

Note that physics web sites generally use equations for an object's position over time. In contrast, the example solution works incrementally, adding small amounts of acceleration and velocity at short time intervals.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset