GALAXY(1)                                               GALAXY(1)

     NAME
          galaxy, mkgalaxy - galactic n-body simulator

     SYNOPSIS
          games/galaxy [ options ] [ -i ] [ file ]
          games/mkgalaxy [ options ] [ -i ] [ -f file ] size

     DESCRIPTION
          Galaxy is an n-body simulator that uses a Barnes-Hut quad-
          tree to calculate gravitational interactions.  Typical usage
          is to read a galaxy file (see galaxy(6)) from standard input
          using the -i command-line option or from a file using the -f
          option. If no file is read then the simulator starts with an
          empty universe.

        Mouse commands
          Holding mouse button 1 while dragging repositions the visi-
          ble region of the galaxy. Holding mouse button 2 while drag-
          ging up or down zooms the visible region of the galaxy in or
          out, respectively.  Mouse button 3 opens a menu with the
          following options:

          new body
               Creates a new galactic body.  Holding button 1 posi-
               tions the body.  Holding a button 1-2 chord changes the
               mass/size of the body. Holding a button 1-3 chord
               changes the initial velocity of the body. Releasing
               button 1 restarts the simulator with the new body in
               motion. When new bodies are created, the simulator
               maintains the Galilean (inertial) reference frame where
               the center of mass of the galaxy is at rest.

          speed
               Prompts for a floating point value to change the speed
               of the simulation. E.g. a value of 2 will double the
               speed of the simulation and a value of 0.5 will halve
               the speed. Accuracy is sacrificed for greater speed.

          gravity
               Prompts for a floating point value to change the gravi-
               tational constant. E.g. a value of 2 will double the
               force exerted by gravity and a value of 0.5 will halve
               it.

          save Prompts for a file name to save the current galaxy as a
               galaxy(6) file.

          load Prompts for a file name to load the galaxy from the
               galaxy(6) file.

     Page 1                       Plan 9            (printed 12/22/24)

     GALAXY(1)                                               GALAXY(1)

          exit Exits the simulator.

        Keyboard commands
          The following keys are recognized as commands:

          a    Show accelerations as vectors.

          v    Show velocities as vectors.

          s    Show statistics such as the number of bodies being sim-
               ulated, the maximum depth of the quad-tree, and the
               average number of calculations made per body.

          q    Exit the simulator.

          space
               Pause and unpause the simulator.

          del  Exit the simulator.

        Command-line options
          Certain aspects of the galaxy simulator are controlled by
          the following options:

          -G gravity
               Sets the gravitational constant to gravity. The default
               value is 1.

          -f file
               Reads the galaxy file file (see galaxy(6)).

          -i   Reads a galaxy file from standard input.

          -p procs
               Specifies the number of extra processes to use in order
               to calculate the gravitational force on each body in
               parallel.  The default value is $NPROC-1.

          -t throttle
               Causes the process that calculates forces to relinquish
               the processor for throttle milliseconds after each cal-
               culation.

          -ε softening
               Sets the softening factor to prevent gravitational sin-
               gularities during collisions or near-collisions. The
               default value is 500.

        Mkgalaxy
          Mkgalaxy is a utility to create galaxies for simulation.
          Galaxies can be assembled incrementally by reading an exist-
          ing galaxy file from standard input with the -i command-line

     Page 2                       Plan 9            (printed 12/22/24)

     GALAXY(1)                                               GALAXY(1)

          option or from a file with the -f option. Mkgalaxy then
          writes to standard output a galaxy(6) file with a galaxy of
          the given size together with the previously read galaxy.
          Galaxies generated by mkgalaxy have characteristics deter-
          mined by the following options:

          -d distance
               Distance determines the spacing between bodies.  The
               default value is 100.

          -s size
               Bodies have the given size. The default value is 25.

          -v velocity
               Bodies have the given velocity in a random direction.
               The default value is 0.

          -av angular velocity
               Bodies have the given angular velocity relative to the
               center of mass of the new galaxy being generated.  The
               default value is 0.

          -gv x,y
               The entire galaxy being generated is given the direc-
               tional velocity determined by the vector (x,y).  The
               default value is (0, 0).

          -o x,y
               The entire galaxy being generated is offset by the vec-
               tor (x,y).  The default value is (0, 0).

          -sq  The galaxy being generated is a square. Without this
               option, the galaxy will be circular.

          The arguments to the -d, -s, -v, and -av arguments have the
          form s or s±r where s and r are double-precision floating
          point numbers.  S is the base value and r if given deter-
          mines a range in which the value will vary randomly from the
          base.

     EXAMPLES
          Two rotating circles destroy each other:

               games/mkgalaxy -av 100 -d 60±50 -v 10 2000 |
               games/mkgalaxy -i -av -70 -d 80±50 -v 10 -o 6000,2000 -gv -80,40 3000 |
               games/galaxy -i

          Cool patterns made by a square galaxy:

               games/mkgalaxy -sq -av 20 5000 | games/galaxy -i

     SOURCE

     Page 3                       Plan 9            (printed 12/22/24)

     GALAXY(1)                                               GALAXY(1)

          /sys/src/games/galaxy

     SEE ALSO
          J. Barnes & P. Hut (December 1986). "A hierarchical O(N log
          N) force-calculation algorithm".  Nature. 324 (4): 446–449.

          galaxy(6)

     HISTORY
          Galaxy and mkgalaxy first appeared in 9front (Feb, 2017).

     Page 4                       Plan 9            (printed 12/22/24)