
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, 0` with zero initial velocity.
* Gravity is `9.8ms^-2` exactly, towards the floor (y positive.)
* The ball weighs `500g` exactly.
* 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 constant coefficient of restitution/bouncyness constant of `0.8` exactly.
* 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:


1. Meets the rules as defined above.
2. Bonus featureness will be considered.
3. Is the shortest and most elegant (subjective decision.)



[Bouncing ball simulation](/questions/10520/bouncing-ball-simulation)
=====================================================================



Python 143 bytes
----------------



```
u=v=x=y=0
a=[[s]*130for s in' '*24+'*']
while x<129:
 if y+v>24:v*=-.8;u=-v
 v+=98e-4;x+=u;y+=v;a[int(y)][int(x)]=s
for r in a:print''.join(r)

```

The resulting curve is slightly different than the example, but this is because the velocity is adjusted before the ball goes into the floor, instead of after it already has.



```
*                                                                                                                                 
*                                                                                                                                 
*                                                                                                                                 
*                                                                                                                                 
*                                                                                                                                 
*                                                                                                                                 
*                                                                                                                                 
*                                                                                                                                 
*                                                                                                                                 
*                     ***************                                                                                             
*                 ****               ****                                                                                         
*               ***                     ***                                                                                       
*             **                           **                                                                                     
*           ***                              **                                                                                   
*         **                                   **                          ******                                                 
*        **                                     **                     ****     *****                                             
*       *                                         **                 ***             ***                                          
*     **                                           **              **                  **                                         
*    *                                               *           **                      **            *********                  
*   *                                                 **        **                        **         ***       ***                
*  *                                                   **     **                            **     ***           **        *****  
* *                                                     **   **                              **   **               **   ***    ***
**                                                       ** **                                ** **                 ** **         
*                                                         ***                                   **                   ***          
**********************************************************************************************************************************

```



---


Python 132 bytes
----------------


A more realistic version, that starts with a constant *x* velocity:



```
v=x=y=0
a=[[s]*130for s in' '*24+'*']
while x<129:v=(y+v<24or-.8)*v+98e-4;x+=.3;y+=v;a[int(y)][int(x)]=s
for r in a:print''.join(r)

```

Produces:



```
****                                                                                                                              
    **                                                                                                                            
     ***                                                                                                                          
       **                                                                                                                         
        **                                                                                                                        
         **                                                                                                                       
          **                                                                                                                      
           *                                                                                                                      
            *                                                                                                                     
            **                   *********                                                                                        
             *                 **        **                                                                                       
              *              **            **                                                                                     
              **            **              **                                                                                    
               *           **                **                                                                                   
               **         **                  **                *****                                                             
                *        **                    **             ***   ****                                                          
                 *       *                      **          **         **                                                         
                 **     *                        *         **            **                                                       
                  *    **                         *       *               **          *******                                     
                  *    *                          **    **                 **      ***       **                                   
                   *  *                            *    *                   **    **           **       *******                   
                   * **                             *  *                     *   **             **    ***     ***      ****       
                    **                              ***                       * *                ** **          **  ****  ****    
                    **                               **                        **                 ***             ***        *****
**********************************************************************************************************************************

```



I'll submit my own solution in Python. Only slightly simplified; I'm sure there are much better ways of doing it! **282 280 characters.** The example output in the question post was generated using this program.



```
import sys;o=sys.stdout.write
py=px=vy=vx=0;g=98e-4;h=25;w=130;k=.8;p=[]
while 1:
 vy+=g;py+=vy;px+=vx
 if py>h:vy=-vy*k;vx=-vy
 if px>w:break
 p.append([int(px),int(py)])
py=0
while py<=h:
 px=0
 while px<w:
  if [px,py] in p or py==h:o('*')
  else:o(' ')
  px+=1
 o('\n');py+=1

```

