Print, on STDOUT, a pattern which shows in what direction a bouncing ball will take.
The following assumptions are made:
- The ball starts at the top left corner:
0, 0with zero initial velocity. - Gravity is
9.8ms^-2exactly, towards the floor (y positive.) - The ball weighs
500gexactly. - The ball bounces at 45 or 135 degrees to the floor unless you want to add the appropriate calculations to add variable trajectories. (Bonus arbitrary points!)
- The ball has a
spring constantcoefficient of restitution/bouncyness constant of0.8exactly. - The ball is perfectly spherical and does not deform when it bounces.
- The room is 25 characters high, 130 characters wide. Each x and y is 1 metre and each ball position represents a discrete sample -- the exact time period is deliberately unspecified, but the display should make the ball's path sufficiently clear. The output should show the path of the ball, not just the final position.
- The floor and ball should be indicated using characters on STDOUT, which may be the same. The presence of no ball or floor surface shall be indicated with a space character.
- You are allowed to assume rounding to three decimal places in any calculations. (Solutions using purely integers may be particularly interested in this rule.)
- The simulation stops when either the ball does not move from the floor or it leaves the room (
x > width of area.) - The program must simulate the ball's path, not simply load it from a file or have it encoded somehow in the program. The test for this will be to optionally change one of the constants. If the program does not calculate a new, correct result, then it does not qualify.
Example output:
*
*
*
*
*
*
*
*
*
* ***********
* ***** ****
* **** ***
* *** ***
* ** **
* *** **
* ** ** *********
* * ** **** ****
* ** * ** **
* * ** ** **
* * * ** ** ********
* ** * ** ** **** ****
* * ** ** ** ** **
* * ** ** ** ** ** **
** ** ** ** ** ** **
* **** **** ***
**********************************************************************************************************************************
Determination of winner. I will accept the answer which:
- Meets the rules as defined above.
- Bonus featureness will be considered.
- Is the shortest and most elegant (subjective decision.)