-----------------
COMETS
By J. E. Charlsen
-----------------

     This program requires the presence of the ARP.Library in the Libs
directory of your system. If it is not there, you may install it by
double-clicking the InstallARPLib icon in the Comet drawer. Before you make
this installation, ensure there are at least 30 free sectors on your system.

     Comets is a toolbelt for celestial tinkers.
     Life can be a bit hectic, but a proven cure for the resultant stress has
been found and is here humbly offered to Amiganauts. It's nothing less that
the opportunity to create a little universe for yourself and watch its
machinations.
     Given the limitations of humans, their monitors and CPU'S, some major
liberties are taken with the size, speed and number of dimensions in the
process. Also, in deference to the inability of some less evolved Amiga
users to visualize the time-space continuum in its entirety, all astral
bodies have comet-like tails to better mark their paths and patterns.

HOW
     The program opens with the title screen containing the following list of
those few keystrokes or mouse manipulations required for macro-tinkering:

     · Click at top of screen to quit, alter objects, scale (+/-), or pause.
     · Clicking on the colored numbers at the top, will give you
self-prompting options of changing (or not) the speed, size and direction of the object
having the same color.
     · Press a number key (1-7) for number of random objects which will
initially be motionless, but soon be "gravitied" into a frenzy.
     · Press "S" or "L" to Save or Load data files of your objects
     · Press "X" to clear the screen
     · Press "Esc" or "Q" to Quit
     · Press "Help" to for title/help screen
     · Top MENUs (right mouse button) for virtual screen size, etc.

     One big built-in "cheat" is the ability to create stationary bodies so
your mini-solar-system will be less likely to fly off the screen. It's
also fun for building solar-systems with two or more "suns". Another
restriction is limiting the speeds which can be attained by the creations.
If an object were to accelerate to some significant
fraction of the speed of light, our computers would expand exponentially
until they'd be bigger than Utah. Don't quote me on that last one, I'm
still working on it, using borrowed Amigas.
     Some interesting arrangements of space-things are stored on the disk.
You may load and alter or just watch them. The real fun is creating
universes, saving them and sharing them with friends, JUMPDISK readers or
the author. If you come up with a "braided ring" system, share it, please!
     The following is a short Basic program listing containing the essential
routines you might like to explore and expand on your own. While I've attached
my initials, I make no claims as to being the originator of the algorithms
or the systems they clumsily attempt to emulate. If we only signed original
programs ... well, there just ain't none!

'------------------  Comet.core.bas    JeC 1/92  ---------------------

  SCREEN 2,640,400,3,4
  WINDOW 2,,,0,2         '--- 640*400, 8 color screen and window

  W2&=WINDOW(2):    W3&=WINDOW(3) '--- Width & height for off-screen checks
  Xmax=W2&: Xmin=0: Ymax=W3&: Ymin=0

  T=5                    '--- T = Number of celestial entities
  DIM Grav(T)            '--- Grav() = Gravity (mass of each object)
  DIM ms%(T)             '--- ms%() = moving or stationary indicator 1 or 0
  DIM pX(T),pY(T)        '--- pX() & pY() = Positions X & Y
  DIM tX(T,50),tY(T,50)  '--- tX() & tY() = Trail of X & Y
  DIM vX(T),vY(T)        '--- vX() & vY() = Velocities

  '--- Read DATA statements for sample solar system 
  FOR i=1 TO T: READ ms%(I),Grav(I),pX(I),pY(I),vX(I),vY(I): NEXT 

  DATA 0, 400, 319, 199, 0, 0
  DATA 1, 0.02250, 462.74329, 67.27353, -1.00055, -0.48634
  DATA 1, 0.00500, 378.54636, 189.57730, 0.53912, -2.69706
  DATA 1, 0.10750, 551.70569, 240.63382, 0.16195, -0.90966
  DATA 1, 0.10000, 385.95480, 202.83722, 0.40809,  2.43635

  '-----------------------------------------------
  '---------------- MAIN LOOP --------------------
  '-----------------------------------------------

WHILE Carrots = BarelyEdible

               '--- check for key press (Esc or Q to quit)
  k$=UCASE$(INKEY$): IF k$>"" THEN IF k$="Q" OR ASC(k$)=27 THEN Bye 

               '--- keep track of number for objects and "tails"
  Head=Count MOD 50:  Tail=(Count+1) MOD 50

  FOR I=1 TO T    '--- Go thru all the objects
    FOR J=1 TO T  '--- calculate gravitational pull of others upon this one

      IF I<>J THEN
        XD=pX(J)-pX(I):     YD=pY(J)-pY(I) '--- X & Y distance from each
        D2=(XD*XD)+(YD*YD): PL=D2*SQR(D2)  '--- How distance affects pull

        IF PL<>0 THEN  '--- If PL=0 we get a "dividing by zero" error
          v1=Grav(J)/PL
          vX(I)=ms%(I)*(vX(I)+v1*XD)
          vY(I)=ms%(I)*(vY(I)+v1*YD)
        END IF

      END IF
    NEXT

    '--- keep the speeds from getting ridiculous
    IF ABS(vX(I))>8 THEN vX(I)=vX(I)*.5
    IF ABS(vY(I))>8 THEN vY(I)=vY(I)*.5

    '--- figure out the new position 
    pY(I)=pY(I)+vY(I):   pX(I)=pX(I)+vX(I)

    '--- make sure it isn't off the screen
    IF pX(I)>Xmax THEN vX(I)=-vX(I): pX(I)=Xmax
    IF pY(I)>Ymax THEN vY(I)=-vY(I): pY(I)=Ymax
    IF pX(I)<0 THEN vX(I)=-vX(I): pX(I)=0
    IF pY(I)<0 THEN vY(I)=-vY(I): pY(I)=0

    '--- remember the position (for erasing the tail 50 moves hence)
    tX(I,Head)=pX(I):  tY(I,Head)=pY(I)
 
    '--- erase the 50th preceding dot drawn
    PSET(tX(I,Tail),tY(Y,Tail)),0 

    '--- draw a dot at the new position
    PSET(pX(I),pY(I)),I

  NEXT '--- then do it for the next object

  '--- a counter for the "tails"
  Count=Count+1: IF Count=2000 THEN Count=0

WEND
'------------------- end main loop ---------------------

Bye: SCREEN CLOSE 2: END
