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.

Source and executable.

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;

Home.