This program simulates an ensemble of gravitating spheres in free space.   They
                collide with each other as hard spheres with a coefficient of friction of 0.2.

                The spheres are shaded dimmer and drawn smaller with distance into the screen.  
                The graphics are very simple: each sphere is drawn as five boundary points at
                regular intervals of time.   The five points drawn are all but the rearmost of
                the six coordinate extremes of each sphere within the simulation's Cartesian
                coordinate system.


                    screens                 source and executable dot zip                 c source dot txt                 solid spheres elastic collision


                UI:

          case 0x1b: quit=1; //Press the escape key to exit the program
          break;
          case '-':
          case '`': clear_screen(); //Clear the screen
          break;
          case '~': vga_mode(19); //reset video mode
          break;
          case ' ': pause=1; //hit spacebar to pause program
          break;
          case '|': steppause=1; //hit ' ' to step in steppause
          break;
          case '%': delnum++; //delay the program's main loop, by one or more milliseconds per loop
          break;
          case '5': {if (delnum!=0) {delnummem=delnum; delnum=0;}  //set main loop delay to zero 
                        else { delnum=delnummem; }  }             //or restore the prior delay
          break;
          case 'T':                           //
          case 't': erasetrails=!erasetrails; //Wipe away previous object draws or not
          break;
          case 'A': zthr*=0.99; if(zthr<1.0)zthr=1.0; //approach unit distance from origin 
          break;                                      //with this perception's z-threshold
          case 'a': zthr+=3.0; //step away from the origin, increasing this projection's 
          break;               //z-threshold distance from the center of the simulated space
          case '[': physdisp=(physdisp+1)%3; //onscreen physics display text readout
          break;
          case 'k': kollisions=!kollisions; //enable/disable particle collisions
          break;
          case 'b': starbreak(); //remove a particle to a distance
          break;
          case 'B': starbreak2(); //drop in another particle
          break;
          case 'o': orbitshot(); //introduce additional particle thrown out and round
          break; 
          case 'r': nstars--; if(nstars==0)nstars=1; //reduce particle number
          break;
          case 'c': centerdists(); //Recenter the momentum and position distributions
          break;
          case 'H': savecopy(); //Save a memory snapshot of the matter simulation
          break;
          case 'h': restoresaved(); //Restore saved matter simulation state
          break;
          case '\\': fpsreadout=!fpsreadout; //Onscreen program speed readout, in frames per second 
          break;
          case '=':               //
          case 'I': nstars=20;    //Twenty particles
          case 'i': init_stars(); //Random distribution of velocities and positions, centered
          break;


                Possible causes of total angular momentum drift: single-precision floating point numbers coming together;
                a small programming mistake in the collision treatment, overwriting one of two factors with the lower
                of the two and partially applying resulting editing to a quadratic equation evaluation; perhaps some
                missing math in the collision treatment to conserve angular momentum; simplicity and size of the
                simulation time step.






                home