Article 12753 of alt.sources:
Path: nntpd.lkg.dec.com!pa.dec.com!src.dec.com!crl.dec.com!crl.dec.com!bloom-beacon.mit.edu!spool.mu.edu!newspump.wustl.edu!crcnews.unl.edu!backbone!backbone!wayne
From: wayne@backbone.uucp (Wayne Schlitt)
Newsgroups: alt.sources
Subject: XStar-2.0.0  Orbiting star system simulator    Part01/06
Date: Sun, 27 Aug 1995 23:07:15 GMT
Organization: The Backbone Cabal
Lines: 1239
Sender: wayne@backbone (Wayne Schlitt)
Message-ID: <WAYNE.95Aug27170715@backbone.uucp>
Reply-To: wayne@cse.unl.edu
NNTP-Posting-Host: cse.unl.edu
Originator: wayne@cse.unl.edu


Submitted-by: wayne@backbone.UUCP
Archive-name: XStar-2.0.0/part01

This program "solves" the n-body problem, and displays the results on
the screen.  It starts by putting a bunch of stars on the screen, and
then it lets the inter-body gravitational forces move the stars
around.  The result is a lot of neat wandering paths, as the stars
interact and collide.

XStar can be used to animate the root window, as a screen saver or just
to display stuff in a regular window.


This is a major rewrite of XStar.  When XStar v1.1.0 was posted in March,
I promised that I would send it to comp.sources.x "if things look ok".
Well, I found a few things that needed fixing, and then a few things
that I wanted to improve, and, well, one thing lead to another and I
ended up rewriting it.  


Major changes since v1.1.0 are:

	* The initial star configurations allow the star systems to
	  last longer and have less early collisions.

	* The star initialization code works very well over a large range
	  of initial numbers of stars.  No more tweaking of constants.

	* Many more types of special star configurations are now generated.

	* After testing many different methods of moving the stars, a
	  faster and much more accurate method was selected.

	* The star bounce code now works reasonably well.

	* Star trails now erase themselves in a non-destructive way.

	* Star trails are now redrawn when the window is exposed.

	* Changing display modes now replots the screen in that mode.

--- cut here ---

# Shell Archive created by backbone!wayne at Sun Aug 27 16:54:50 1995

# To unpack the enclosed files, please use this file as input to the
# Bourne (sh) shell.  This can be most easily done by the command;
#     sh < thisfilename

# This archive contains;
#  README           xstar.1             Imakefile           README.xgrav        
#  COPYING          theory_of_op.ltr    xstar.c             init_stars.c
#  init_colors.c    global_vars.c       check_bounce.c      animate.c           
#  collide.c        sys_const.c         default_init.c      set_sys_param.c
#  set_xmva.c       update_screen.c     plot_collapsars.c   reset_hstep.c
#  set_star_disp.c  move_stars_taylor3.cmove_stars_rk4.c    move_stars_gpemce8.c
#  move_stars_ab7.c move_stars_am7.c    dump_sys.c          init_sys_4.c
#  init_sys_8.c     init_sys_8b.c       xstar.h             patchlevel.h        
#  vroot.h          xstar_ext.h         plot_star.h


# ---------- file README ----------

filename="README"

if [ -f $filename ]
then
  echo File \"$filename\" already exists\!  Skipping...
  filename=/dev/null		# throw it away
else
  echo extracting file README...
fi

cat << 'END-OF-FILE' > $filename
XStar by Wayne Schlitt, wayne@backbone.UUCP (wayne@cse.unl.edu)


This program "solves" the n-body problem, and displays the results on
the screen.  It starts by putting a bunch of stars on the screen, and
then it lets the inter-body gravitational forces move the stars
around.  The result is a lot of neat wandering paths, as the stars
interact and collide.

XStar can be used to animate the root window, as a screen saver or just
to display stuff in a regular window.



All comments, bug reports, bug fixes, enhancements, etc are welcome.
Send them to me at wayne@backbone.uucp or wayne@cse.unl.edu.


This program is really a heavily modified version of XGrav, which was
written by David Flater (dave@case50.ncsl.nist.gov) and posted to
alt.sources on 1/21/95.  I liked the program enough that I was really
interested in it, but I didn't like it enough to leave it alone.  The
idea was Dave's, but I don't think too much of his code has been left
unchanged.  There is probably more untouched code from XSwarm, which
Dave used to implement the X port of his n-body problem solving code.

Like XGrav, any claim to this program that I have (which isn't much)
is under the GNU General Public License.  Have fun with it.


Changes to XStar
----------------
Version 1.0.0	3/12/95
	* initial release to alt.sources

Version 1.1.0	3/22/95
	* second release to alt.sources
	* the runtime 'd' command could cause a divide by zero
	* fixed up an error msg when allocating colors
	* portability patches for HPUX and AIXV3
	* GPL license is included in the shar file
	* switched to the rand48() family of random number generators
	* a 'multi-color' mode as added so that each star could have
          it's own color.  Can be enabled with the -m option.
	  (From Jeffrey Mogul <mogul@pa.dec.com>)
	* run time commands 'm' and 'r' to toggle between multi-colored
	  and rainbow modes. (From Jeffrey Mogul <mogul@pa.dec.com>)
	* Jeff Mogul also created a man page for XStar.
	* Don't start collapsars at exactly the COLLAPSAR mass to avoid
	  FP rounding problems.
	* I found, to my shock and horror, that the code I inherited from
	  xgrav implemented some sort of Aristotelean physics where
	  heavier objects fell faster than lighter objects.  Converting to
	  Newtonian physics made things slightly slower, but I think
	  more interesting.
	* XGrav calculated the new locations of the stars by using the
	  formula:  x(t) = x0 + v t
	  This assumes that the velocity is constant (it isn't).
	  Instead, I now use:  x(t) = x0 + v t + 1/2 a t^2 + 1/(2*3) (Dt a) t^3
	  This assumes that the derivative of the acceleration is
	  constant (it isn't).  At least it is _closer_ to being correct.
	  Even dropping the term with the first derivative of the acceleration
	  makes the movement _much_ less accurate.
	* changing to Newtonian physics makes the experimental bounce code
	  work much better, but it still doesn't work very well.
	* added the -a and -m options to let people tweak the FV and FM
	  values without having to recompile the system.

Version 2.0.0 8/27/95

	This was a major rewrite of XStar.  The three major parts of
        XStar namely, the initial star configuration code, the star
        movement code and the display code, have all undergone major
        reanalysis, redesign and recoding.  The whole program has been
        broken apart and modularized.

	Major changes:

	* The initial star configurations allow the star systems to
	  last longer and have less early collisions.

	* The star initialization code works very well over a large range
	  of initial numbers of stars.  No more tweaking of constants.

	* Many more types of special star configurations are now generated.

	* After testing many different methods of moving the stars, a
	  faster and much more accurate method was selected.

	* The star bounce code now works reasonably well.

	* Star trails now erase themselves in a non-destructive way.

	* Star trails are now redrawn when the window is exposed.

	* Changing display modes now replots the screen in that mode.

	In addition, many many minor changes and bug fixes were made.


	James da Silva (jds@cs.umd.edu) contributed code to do self
	erasing trails, but I ended up not using it and instead
	implemented a different method that allowed for a
	non-destructive erasure.  The contribution was still very
	appreciated since it allowed me to see what it would look
	like with destructive erasing.


	Working on XStar has been a fun project that helped me refresh
	my understanding of classical mechanics (physics), differential
	equations, numerical analysis, X programming, and data structures.
	It has also given me some insight into the dynamics of star clusters
	galaxies and the physics of bouncing objects.

   


Changes from XGrav (vs XStar 1.0.0)
------------------

Performance improvements and bug fixes:

- XGrav used some sort of Aristotelian physics where heavier objects fell
  faster than light objects.  I switched to Newtonian physics.

- Lots of work was done to make the calculation of new star positions
  more efficient.  It looked like some of the collisions weren't
  working right, so I threw out Dave's calculations and re-derived
  my own.  I found out that Dave's code was correct, but slightly
  slower than mine and the problems with collisions was elsewhere.

  Anyway, after a lot of rewriting, the net result is that XStar can
  calculate many more interactions per second than XGrav could.

- The gravitational constant has been replaced with fudge factors that
  are easier to adjust.  These fudge factors have been cranked up to
  make the simulation many times more accurately.

  This increased accuracy prevents stars from shooting off at very
  high velocities instead of colliding like they should and it also
  allows collapsars to be orbited easier.  As a result, collapsars no
  longer eat most of the stars in the system, and thus the runtime 'd'
  command is much more useful.

  This change slows things down, but the other speed increases more than
  offset this.

- I changed the star trails from thick lines to single pixel width
  lines so that you can see more intricate interactions between the
  stars. I also buffer the output to the X server, and I don't
  check for X events as often.  This reduces the cpu consumed by the
  kernel and the X server by a huge amount.  This, in turn, allows you
  to run XStar at a very low priority and it won't have as big of an
  impact on other processes.  (The kernel and the X server always run
  at a high priority.)

- The default number of stars has been upped from 9 to 15.

- The delay option (-D msec) no longer slows the program down by a
  huge amount, so it is actually fairly useful now.

- Stars that float too far away from the center are now forgotten
  about.  They don't have much affect when they are way out there and
  they just slow things down.

The net result is that XStar simulates more stars, more accurately and
much quicker than XGrav could.


New bells and whistles  (XGrav vs XStar 1.0.0)
----------------------

- XStar tries to detect when "interesting" things are no longer
  happening on the screen and creates a new star system automatically.
  It no longer waits for a fixed amount of time before restarting.

- The initial star configuration code is much more sophisticated.  It
  randomly creates 0 to 4 collapsars and adjusts the masses and
  velocities of the initial stars to compensate.  It puts a
  counter-clockwise spin on the system so that the stars tend to orbit
  each other instead of just collapsing toward the center or flying
  off the screen.  The initial configuration seems to be fairly good
  for a wide range of the initial number of stars (-b num).

- The -v, -R command line options are new, as are the run time
  commands n, +, - and p.  The support of -r using the -g values is
  also new.



Known Bugs and Missing Features
-------------------------------

- It has been suggested (michael@dsndata.com) that it would be neat if
  collisions could cause the stars to break apart into several pieces.

  Maybe we could do something like if they collision is very softly, the
  particles stick together, but if they collide with a fair amount of
  force, they bounce.  If they collide with even more force, then they
  break apart.  This could let a single "system" evolve for quite a
  while.

- It would be nice if XStar detected heavy loads on the system and
  slowed down the updates during those times.  Unfortunately, it looks
  like about the most portable way of determining the loadavg would be
  to run uptime and parse the output.  This is kind of expensive to do.

  So, XStar works ok as a background process in the root window, but
  sometimes you have to hit 'p' to let other things get done sooner.

- I wasn't able to get the save-under feature to work in the root
  window, nor did the screen saver work correctly for me.  I think
  this is a problem with my (old) X Server, rather than a bug in the
  code.

- I think it would be neat to plug in the values for the solar system
  and see what happens.  By using the value for G and any arbitrary
  number of pixel distances, we can obtain conversion factors for the
  mass and distances.  Time is defined such that each iteration takes
  one unit of time

- It might be nice to use the mouse to create stars or temporary collapsars.
  You could click the mouse down and then the stars would follow the
  cursor around.  It would kind of be like XSwarm.

- Extend this to 3-d and use the color to denote the z distance

- need to add a toggle to change from short to long tails.  (maybe no tails
  also?)

- add a mode that uses the mass to determine the color of the star

- create positive and negative attraction like electrical forces

- keep track of the energy stored when two stars collide hand have
  them spontaneously decay into two stars, kind of like how
  sub-atomic particles do.

- create a circular star system with 2-3 rings of stars

- create a circular star system made of binary stars

- shouldn't plot_collapsars use a XDrawRectangle() instead of plotting
  the individual points?

- why doesn't the star_line stuff stay symmetric?  The points are carefully
  centered around zero...

END-OF-FILE

if [ "$filename" != "/dev/null" ]
then
  size=`wc -c < $filename`

  if [ $size != 10272 ]
  then
    echo $filename changed - should be 10272 bytes, not $size bytes
  fi

  chmod 660 $filename
fi

# ---------- file xstar.1 ----------

filename="xstar.1"

if [ -f $filename ]
then
  echo File \"$filename\" already exists\!  Skipping...
  filename=/dev/null		# throw it away
else
  echo extracting file xstar.1...
fi

cat << 'END-OF-FILE' > $filename
.TH XSTAR 6 "August 27, 1995"
.UC 4
.SH NAME
XStar Version 2.0 \- X11 animated n-body solver
.SH SYNOPSIS
.B xstar
.B [\-hrRMv]
.B [\-b
.I stars]
.B [\-g
.I geometry]
.B [\-d
.I host:display]
.B [\-t
.I timeout]
.B [\-D
.I delay]
.B [\-B
.I buf_factor]
.B [\-c
.I star_color]
.B [\-C
.I bg_color]
.B [\-a
.I float]
.B [\-m
.I [taylor3|rk4|gpemce8|ab7|am7]]
.B [\-l
.I float]
.B [\-T
.I num_pts]

.SH DESCRIPTION
.I XStar
is an X11 client that ``solves''
the n-body problem, and displays the results on
the screen.  It starts by putting a bunch of stars on the screen, and
then it lets the inter-body gravitational forces move the stars
around.  The result is a lot of neat wandering paths, as the stars
interact and collide.
.PP
.SH OPTIONS
.I XStar
has the following options:
.TP
.B \-h
Display the usage message and exit.
.TP
.BI \-b " stars"
Select the number of stars to initially have in the star
system.  The default is 15 stars, the minimum is 2 and the maximum is 249.
.TP
.B \-r
Use root window.
.TP
.BI \-g " [=][<width>x<height>][{+-}<xoffset>{+-}<yoffset>]"
Selects the initial window size and location.  If the \-r
option is also selected, then the offset is used to move
the "center of the star system" around.  That is, you can
use the \-g option to move the interesting stuff to a free
spot of your screen.
.TP
.BI \-d " host:display"
As in \-d spacsun:0.0 or \-d unix:0.0.
.TP
.BI \-t " timeout"
Use XStar as your screen saver with the given no-activity
timeout value (in seconds).
.TP
.BI \-D " delay"
Periodically wait for 'delay' milliseconds to keep from using
100% of the CPU.  The default is 0 ms.  This doesn't always work incredibly
well to reduce the CPU usage because most Unix schedulers notice that
XStar is not using as
much CPU as it could and they increases XStar's priority.  On the other hand,
it does make the display rate vary less as collisions decrease the number
of stars.
.TP
.BI \-c " star_color"
Select the color of the stars.  The default is White.
.TP
.BI \-C " bg_color"
Select the color of the background.  The default is Black.
.TP
.B \-R
Rotate the star colors through the Rainbow.  Very pretty, but
uses up 48 color slots.  This causes each star track to change
colors as time passes, but at any given time, all stars have the same
color.  Also available with the 'r' runtime command.
.TP
.B \-M
Assign multiple star colors.  Also uses up 48 color slots.
At any given time, each star has a unique color (unless there are too
many stars to do this).  This makes it much easier to see where
a star has been.  Also available with the 'm' runtime command.
.TP
.BI \-a " value"
Adjusts the accuracy of the position calculations by a factor of ``value''.
The larger the value, the more accurately XStar simulates the real world but 
the slower it runs.  The value can be any floating point number greater
than zero.  The default value is 1.0.  Any value greater than zero is valid,
with values below 1 decreasing the accuracy and values above one increasing it.
.TP
.BI \-m " taylor3|rk4|gpemce8|ab7|am7"
Selects the method to use for updating the star locations and velocities.
The default method is ab7.
.RS
.TP
.B taylor3
Use a taylor series expansion to get an order 2 method, but then uses previous
acceleration values to extend it to a 3rd order method.  This method is the
fastest method and for accuracies below .8 (-a .8), it is also the most
accurate.
.TP
.B rk4
Use the Runge-Kutta method of 4th order.  It is over 4 times as slow as
taylor3, but it is not 4 times as accurate.  It is used internally to 
initialize the taylor3, am7 and ab7 methods.
.TP
.B gpemce8
Use an 8th order Gragg's polynomial extrapolation method
with modifications
for conservation of energy to make it a discrete mechanics method.  This is
by far the most accurate method, and when it's accuracy breaks down, the 
resulting star system preserves the constants of motion, that is, it conserves
the energy of the system, the center of gravity, the linear and angular
momentum, etc.  It is also by far the slowest method and probably not useful
except on a very fast machine or when you are using it as a benchmark to
compare other methods.
.TP
.B ab7
Use a 7th order Adam-Bashford method.  This is the default and for accuracies
in the range of .8 to 4, it is the most efficient method.  It is slightly slower
than the taylor3 method, especially when there are only a few stars.
.TP
.B am7
Use a 7th order Adam-Moulton predictor-corrector method.  It is about twice
as expensive as ab7, and not a whole lot more accurate.
.RE
.TP
.BI \-l " float"
The minimum distance between stars before they collide.  The default is one
pixel.  This value should be increased when decreasing the accuracy.  You
can also decrease the collision distance to be less than one pixel if you
greatly increase the accuracy, but results can be confusing since entire loops
could be contained within a single pixel.  If this value is set too small for
the current accuracy, then the star system will star displaying strange
behaviors.
.TP
.BI \-T " num_pts"
The number of points to display as star trails.  The default is 16384 points,
the minimum is 512 and the maximum is 24575.  If you use a value less than
the minimum, then no points will be remembered.  Instead, the star trails
will not erase themselves and the screen will be periodically cleared.
Using the \-T 0 option will greatly reduce the memory requirements of XStar.
.TP
.BI \-B " buf_factor"
This changes the amount of buffering to be done with the X server.  The
default is 1.0, but any number greater than zero can be used to increase or
decrease the buffering.  If the stars appear to move in a jerky fashion, then
you should decrease the buffering to a value between 0 and 1.  If there is
too much server/network load being generated by XStar, then increase the
buffering factor.
.TP
.B \-v
Display verbose internal debugging information.  Several \-v
options	will make XStar more verbose.
.SH RUN TIME COMMANDS
When XStar is running, it will accept a few commands from the
keyboard.  They are:
.TP
.B "d"
Add an immobile collapsar/gravity well.
.TP
.B "e"
Erase the star trails.
.TP
.B "n"
Reinitialize the star system with a new set of stars.
.TP
.B "+"
Add a star to the current star system.  All future
star systems will also have an additional star.
.TP
.B "-"
Delete a star from the current star system.  XStar
will try to delete the "least interesting" star.
Often the deleted star will be off the screen.  All future star
systems will also have one less star.
.TP
.B "m"
Toggle to ``multiple color mode'', where each star has its own color.
.TP
.B "r"
Toggle to ``Rainbow mode'', where the stars will change color with time.
.TP
.B "p"
Pause the updating of the screen.  Actually, XStar will continue to
update the screen, but there will be a 3 second delay
between updates.  This is useful if XStar is using up
too much CPU and you want to stop it for a short period of time.
.sp
Press p again to return to full speed.
.TP
.B "q"
Quit running XStar.
.SH HELPFUL HINTS
If you find the system running too quickly, you can do any
of the following
things:
.TP
.B "1)"
Use the \-D option to add a delay between updates.  This also keeps
XStar from using 100% of the CPU. 
.TP
.B "2)"
Use the \-a option to increase the accuracy of the system.
.TP
.B "3)"
Use the \-b option to add additional stars.  Doubling the number of
stars will make XStar run about 4 times as slow.
.TP
.B "4)"
If you have increased the accuracy, you can then also slightly decrease
the collision distance with the \-l option.  Don't over do it though, or
you will
start seeing strange things happen.
.TP
.B "5)"
Use the \-m option to select a more accurate, but less efficient method
such as rk4 or gpemce8.
.sp 2
.LP
If you find the system running too slowly, you can do any of the following
things:
.TP
.B "1)"
Use the \-b option to decrease the number of stars.
.TP
.B "2)"
Use the \-a option to decrease the accuracy of the system.  You probably will
want to change the collision distance a little bit also by using the -l
option.
.TP
.B "3)"
Use the \-m option to select a less accurate, but faster method namely
taylor3.  If you decrease the accuracy below .8, taylor3 will be more accurate
than ab7.
.TP
.B "4)"
Buy a faster computer, get a better optimizer for your compiler, or implement
a faster method of calculating the star locations.
.sp 2
.LP
If you find the that XStar is using too much memory, you can do any of the
following:
.TP
.B "1)"
Use the \-T 0 option to eliminate the star trails.  (Saves about 200k.)
.TP
.B "2)"
Do not use rainbow mode or multi-color mode.  (Saves a little bit)
.TP
.B "3)"
Recompile XStar to use a smaller value for HASH_TABLE_BITS.
.SH AUTHOR
XStar's author is Wayne Schlitt, wayne@backbone.UUCP (wayne@cse.unl.edu)
.LP
All comments, bug reports, bug fixes, enhancements, etc are welcome.
Send them to me at wayne@backbone.uucp or wayne@cse.unl.edu.
.LP
This program started out as a heavily modified version of XGrav, which was
written by David Flater (dave@case50.ncsl.nist.gov) and posted to
alt.sources on 1/21/95.  I liked the program enough that I was really
interested in it, but I didn't like it enough to leave it alone.  The
idea was Dave's, but I think that very little of his code is left.
There is probably more code left from XSwarm, which
Dave used to implement the X port of his n-body problem solving code.
Xswarm's author is Jeff Butterworth (butterwo@cs.unc.edu).
.LP
Like XGrav, any claim to this program that I have (which isn't much)
is under the GNU General Public License.  Have fun with it.
.LP
Documentation converted to ``man'' format by Jeff Mogul (mogul@wrl.dec.com),
who also added the \-m option.
END-OF-FILE

if [ "$filename" != "/dev/null" ]
then
  size=`wc -c < $filename`

  if [ $size != 9729 ]
  then
    echo $filename changed - should be 9729 bytes, not $size bytes
  fi

  chmod 660 $filename
fi

# ---------- file Imakefile ----------

filename="Imakefile"

if [ -f $filename ]
then
  echo File \"$filename\" already exists\!  Skipping...
  filename=/dev/null		# throw it away
else
  echo extracting file Imakefile...
fi

cat << 'END-OF-FILE' > $filename
#
# Possible options:
#
# -DNUM_COLORS=<num>	number of colors to use.  Default is 48, max is 64
#			
# -DHASH_TABLE_BITS=<num>	number of bits used to store indexes into the
#			hash table.  The default is 15, the maximum (without
#			some recoding) is 16.  The larger this number, the
#			larger the hash table will be and the more point
#			locations will saved.
#
#			The default of 15 uses 64k for the hash table and
#			128k for points.
#
# -DNEEDS_TYPEDEFS	define if the typedefs uint_t etc are not automatically
#			defined for you.  (HPUX 8.0 needs this)
#
# -DUSE_USLEEP		use usleep() instead of nap().  (needed for HPUX)
#
# -DRAND48_PROTO	give prototypes for the *rand48() functions.  (needed
#			for HPUX)
#

#CCOPTIONS =


DEPLIBS = $(DEPXLIB)
LOCAL_LIBRARIES = $(XLIB)
LDLIBS = -lm


HDRS    = xstar.h patchlevel.h vroot.h
HDREXTS = xstar_ext.h plot_star.h

MOVE	= move_stars_taylor3.c move_stars_rk4.c \
	move_stars_gpemce8.c move_stars_ab7.c move_stars_am7.c 

SYS	= dump_sys.c init_sys_4.c init_sys_8.c init_sys_8b.c

SRCS    = xstar.c init_stars.c init_colors.c global_vars.c \
	  check_bounce.c animate.c collide.c sys_const.c default_init.c \
	  set_sys_param.c set_xmva.c update_screen.c plot_collapsars.c \
	  reset_hstep.c set_star_disp.c

AUX	= README xstar.1 Imakefile \
	  README.xgrav COPYING theory_of_op.ltr
OBJS    = $(SRCS:.c=.o) $(MOVE:.c=.o) # $(SYS:.c=.o) 


ComplexProgramTarget(xstar)

shar:
	shar -s 64000 $(AUX) $(SRCS) $(MOVE) $(SYS) $(HDRS) $(HDREXTS)
	rename "s/SH-Archive/xstar.part/" SH-Archive*

$(OBJS)::	$(HDRS)

$(MOVE:.c=.o)::	plot_star.h
END-OF-FILE

if [ "$filename" != "/dev/null" ]
then
  size=`wc -c < $filename`

  if [ $size != 1586 ]
  then
    echo $filename changed - should be 1586 bytes, not $size bytes
  fi

  chmod 660 $filename
fi

# ---------- file README.xgrav ----------

filename="README.xgrav"

if [ -f $filename ]
then
  echo File \"$filename\" already exists\!  Skipping...
  filename=/dev/null		# throw it away
else
  echo extracting file README.xgrav...
fi

cat << 'END-OF-FILE' > $filename
XGrav by DWF, dave@case50.ncsl.nist.gov
Version 1.0.1, 1/20/95

This program is a hack of XSwarm 2.3 by Jeff Butterworth.  I know nothing
about X programming, so I modified a program that was pretty close to what I
wanted.

Instead of a swarm of bees, this program now shows the gravitational
interaction between a number of "stars."  The trails are left on purpose
since I think it's more interesting that way.

Insofar as I have any claim to this program (and I haven't much since it's
a hack of somebody else's) the GNU General Public License would apply.  My
contributions here are free, but they come with absolutely no warranty and
nobody can get a patent on them.

Command Line Options
--------------------

         -h|q|?            display this message
         -r                use root window
         -g geometry       window geometry
         -d host:display   X server to connect to
         -t timeout        screen saved after 'timeout' seconds
         -D delay          non-blocking delay between updates (milliseconds)
         -b stars          number of stars
         -c star_clr       star color
         -C bg_color       background color

         Press d in the window to add a gravity well.
         Press e in the window to erase trails.
         Press q in the window to quit.

Helpful Hints
-------------

1.  The default delay is 0.  Setting a nonzero delay slows it down a lot.
    To slow it down a little, add stars.

2.  You get nine stars by default.  The area over which the stars are
    distributed when you start up gets bigger the more stars you ask for.
    Too many stars too close together results in everything falling into
    a black hole, which is not so entertaining.  The default window size
    is always 512x512, so you might want to specify a bigger window if you
    have a lot of stars.

3.  In screensaver or root window mode, the program automatically starts
    over every 2 minutes; otherwise it runs until you stop it.  The
    keypress commands (d, e, q) only work in normal window mode.

4.  The d command adds a stationary gravity well.  Since its position is
    fixed it is easier to see elliptical orbits when they happen.  The d
    is for destroy, since most of the stars won't orbit but will fall
    right in.  Press d several times in a row to see some interesting
    trajectories.

5.  The e command is for erasing the old trails in case the screen gets
    cluttered and you can't see what is happening.

Known Bugs
----------

The pointer interferes with the screensaver.

Big enough collapsars will become stationary like gravity wells.

Collisions sometimes don't look right.

Root window mode may not work on SGIs.

History
-------

Updated README 1/20/95.


Version 1.0 patch 1, 1/17/95.  Don't include getopt.h on Suns -- it ain't
there.  Show patchlevel in title bar.  Reduced the amount of energy absorbed
in a collision from 50% to 25%.  Removed gcc-specific -Wall from Imakefile.


Version 1.0, 1/15/95.  This is actually the fifth time I have implemented an
n-body program.  The first implementation was in BASIC on a VIC-20.  It didn't
work very well.  I thought there was something I was missing in the algorithm.
In retrospect, the algorithm was correct; what I did wrong was set the
gravitational constant too high because I wanted to be able to see things
moving on the screen.  The VIC-20 could not do enough iterations per second to
get acceptable accuracy in real time.  The smaller the gravitational constant,
the greater the accuracy but the slower the motion.

The second implementation was a parallel version in Occam on a Transputer
hypercube.  That one was a project for a parallel programming class.  It worked
pretty well, but it was a short victory since it was about the least portable
code I've ever written.  This led immediately to the third implementation,
which was a rewrite of the VIC-20 BASIC on a Commodore 128 to behave more like
the Occam version.  It worked, but it was too slow.

The fourth implementation happened when I got my 386, under Turbo C++.  None of
Borland's spiffy graphics drivers did what I needed, so I just POKEd the pixels
into display memory like I did on the Commodore.  I later changed that program
slightly to compile under GCC (DJGPP).  The syntax was different, but I was
still using direct graphics.

Now I have finally gotten stupid enough to blow a weekend getting it to run
under X.  This is the fifth implementation.  The sixth one will probably be in
3-D.
END-OF-FILE

if [ "$filename" != "/dev/null" ]
then
  size=`wc -c < $filename`

  if [ $size != 4503 ]
  then
    echo $filename changed - should be 4503 bytes, not $size bytes
  fi

  chmod 660 $filename
fi

# ---------- file COPYING ----------

filename="COPYING"

if [ -f $filename ]
then
  echo File \"$filename\" already exists\!  Skipping...
  filename=/dev/null		# throw it away
else
  echo extracting file COPYING...
fi

cat << 'END-OF-FILE' > $filename
		    GNU GENERAL PUBLIC LICENSE
		       Version 2, June 1991

 Copyright (C) 1989, 1991 Free Software Foundation, Inc.
                          675 Mass Ave, Cambridge, MA 02139, USA
 Everyone is permitted to copy and distribute verbatim copies
 of this license document, but changing it is not allowed.

			    Preamble

  The licenses for most software are designed to take away your
freedom to share and change it.  By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users.  This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it.  (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.)  You can apply it to
your programs, too.

  When we speak of free software, we are referring to freedom, not
price.  Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.

  To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.

  For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have.  You must make sure that they, too, receive or can get the
source code.  And you must show them these terms so they know their
rights.

  We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.

  Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software.  If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.

  Finally, any free program is threatened constantly by software
patents.  We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary.  To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.

  The precise terms and conditions for copying, distribution and
modification follow.



















		    GNU GENERAL PUBLIC LICENSE
   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

  0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License.  The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language.  (Hereinafter, translation is included without limitation in
the term "modification".)  Each licensee is addressed as "you".

Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope.  The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.

  1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.

You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.

  2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:

    a) You must cause the modified files to carry prominent notices
    stating that you changed the files and the date of any change.

    b) You must cause any work that you distribute or publish, that in
    whole or in part contains or is derived from the Program or any
    part thereof, to be licensed as a whole at no charge to all third
    parties under the terms of this License.

    c) If the modified program normally reads commands interactively
    when run, you must cause it, when started running for such
    interactive use in the most ordinary way, to print or display an
    announcement including an appropriate copyright notice and a
    notice that there is no warranty (or else, saying that you provide
    a warranty) and that users may redistribute the program under
    these conditions, and telling the user how to view a copy of this
    License.  (Exception: if the Program itself is interactive but
    does not normally print such an announcement, your work based on
    the Program is not required to print an announcement.)


































These requirements apply to the modified work as a whole.  If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works.  But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.

Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.

In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.

  3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:

    a) Accompany it with the complete corresponding machine-readable
    source code, which must be distributed under the terms of Sections
    1 and 2 above on a medium customarily used for software interchange; or,

    b) Accompany it with a written offer, valid for at least three
    years, to give any third party, for a charge no more than your
    cost of physically performing source distribution, a complete
    machine-readable copy of the corresponding source code, to be
    distributed under the terms of Sections 1 and 2 above on a medium
    customarily used for software interchange; or,

    c) Accompany it with the information you received as to the offer
    to distribute corresponding source code.  (This alternative is
    allowed only for noncommercial distribution and only if you
    received the program in object code or executable form with such
    an offer, in accord with Subsection b above.)

The source code for a work means the preferred form of the work for
making modifications to it.  For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable.  However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.

If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.































  4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License.  Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.

  5. You are not required to accept this License, since you have not
signed it.  However, nothing else grants you permission to modify or
distribute the Program or its derivative works.  These actions are
prohibited by law if you do not accept this License.  Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.

  6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions.  You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.

  7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License.  If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all.  For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.

If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.

It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices.  Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.

This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
































  8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded.  In such case, this License incorporates
the limitation as if written in the body of this License.

  9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time.  Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.

Each version is given a distinguishing version number.  If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation.  If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.

  10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission.  For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this.  Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.

			    NO WARRANTY

  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.

  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.

		     END OF TERMS AND CONDITIONS




































	Appendix: How to Apply These Terms to Your New Programs

  If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.

  To do so, attach the following notices to the program.  It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.

    <one line to give the program's name and a brief idea of what it does.>
    Copyright (C) 19yy  <name of author>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

Also add information on how to contact you by electronic and paper mail.

If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:

    Gnomovision version 69, Copyright (C) 19yy name of author
    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
    This is free software, and you are welcome to redistribute it
    under certain conditions; type `show c' for details.

The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License.  Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.

You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary.  Here is a sample; alter the names:

  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
  `Gnomovision' (which makes passes at compilers) written by James Hacker.

  <signature of Ty Coon>, 1 April 1989
  Ty Coon, President of Vice

This General Public License does not permit incorporating your program into
proprietary programs.  If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library.  If this is what you want to do, use the GNU Library General
Public License instead of this License.
END-OF-FILE

if [ "$filename" != "/dev/null" ]
then
  size=`wc -c < $filename`

  if [ $size != 17982 ]
  then
    echo $filename changed - should be 17982 bytes, not $size bytes
  fi

  chmod 660 $filename
fi

echo end of this archive file....
exit 0
--- cut here ---
-- 
Wayne Schlitt can not assert the truth of all statements in this
article and still be consistent.


