bomb - automatic interactive visual stimulation
Scott Draves <spot@cs.cmu.edu>
http://www.cs.cmu.edu/~spot
see the file COPYING for the license covering this software.
see below for the license covering the output of this software.

this program is for svgalib (on linux), with working ports to X11,
OpenGL, the Power Mac, and win32.

see manual.txt for instructions about how to run and use bomb.

see http://hopeless.mess.cs.cmu.edu:8001/bomb/index.html and
http://hopeless.mess.cs.cmu.edu:8001/nab/nab.html for online
documentation, explanation, and discussion.

i apologize for the quality of this code.  it is very low.  i use this
project as a garbage dump for my worst coding impulses.  this helps
keep the rest of my code cleaner.  no kidding.

chunks of code and various rules have been taken from various sources
(i'm always looking for more stuff, so email if you have something
that you think fits). contributors/sources include:

jepler@herbie.unl.edu  originally derived from vga_eyecandy
tcl@sgi.com            rotor idea
nix@cs.cmu.edu         wisps, waves, fade2cmap, many suck/*.gif
ehn@cs.cmu.edu         gifs
Jim Frost              xli header file (copyright below)
Kirk L. Johnson        gif code (copyright below)
Torben Mogensen        idea for symmetric life
ajw@cs.cmu.edu         lots of help for all sorts of mac things
rus@apple.com          mac sound code originally from cthugha

thanks to nix for many interesting discussions and don
hopkins@interval.com for inspiration.  thanks to toffoli and margolus
for their excellent book _cellular automata machines_ (isbn
0-262-20060-0, or see http://www.im.lcs.mit.edu/cam8).  thanks to
the graphics lab at CMU SCS for the use of their fine hardware.

-----------------------

license covering output:

`bomb' is covered by the GNU GENERAL PUBLIC LICENSE, but as noted on
line 75:

	... 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.

in the case of `bomb', the output *is* considered to be derived from
the bomb itself and its datafiles.  i place the following restrictions
on its use:

1) you may not publicly exhibit it.
2) you may not record it.
3) you may not make any money with it.

if you want to do any of these things, contact me, and i'm sure we can
work something out. depending on circumstances, my terms are generally:

1) you must notify me in advance
2) you must give me credit
3) you must give me a cut of any money you make

-----------------------

release 1.13

added MPEG output with code from the MPEG Software Simulation Group
(http://www.mpeg.org/MSSG/) (SGI version only).
preliminary release for win32 API.  second win32 release 10/5.
third win32 release 10/21---included are bomb.exe and the screen-saver
bomb.scr.  fourth win32 release 11/21---direct draw version.  still
no sound input.  removed screen saver.  added new mode:  RD2.
release 12/1 sound input mostly working.  added image-driven masking
to static.  12/5 sound input apparently working.  added a about five
more eskimo masks and two islamic patterns.

release 1.12, as of Sep 18, 1996
added several new suck/*, especially masks.  added sound input to SGI
and Mac (mac code from cthugha), hooked up to diffusion-speed and
flame-drift.  it can't yet tell if the device is present but no music
is playing, so it doesn't always use the sound input on the
diffusion-speed, since it is also good without it.  use 'n' to toggle
this.  added triangular tilings for RD textures.  blocks on title page
waiting for keystroke.  implemented mac version of fname2fnum to fix
'Z'. (released on mac only)


release 1.11, as of May  6 1996
location of data files now a variable in makefile as requested by
joey@kite.preferred.com.  'm' in image rule like 'b' but follows image
sequence.  in Makefile, added tiff.h tiffio.h, and dependencies to
DIST, made linux version link statically.  autorule fixed (was
starting at 3 not 4), fiddled with auto_mode basically to make rule_rd
work better.  changed how rhythm is used by the flame/rotor.  mac
version in cludes `big bomb' which runs at 640x400.

release 1.10, as of Mar 25 1996
added cmap_path, added rule_rd to preferred list.  added rotating
spiral to rd and slip.  added new image2grad, used in rd and slip..
fill_board in slip works.  adjusted hist to ignore edges of screen, so
it detects empty slip board from expansion.  fixed board doubling.
added pixel replication on the mac, but it's much too slow, and the
cmaps are broken.  added v simple mouse input on mac.

release 1.9, as of Mar 10 1996
handles tiff images via libtiff, converted suck/* and title* to tiff.
it only accepts tiff images in IBM-PC order (i think this is a fault of
TIFFReadRGBAImage).  libtiff is the work of Sam Leffler	(sam@engr.sgi.com)
and can be found at ftp://ftp.sgi.com/graphics/tiff.  various
new diffusion patterns for RD textures, including prototype gradient
mode.  properly refresh screen on exit on mac.

release 1.8, as of Feb 7 1996
parameterized RD to various diffusion patterns, including driving by
image.  RD dithers between kernels to allow any angle (eigenvectors)
(try `dP6 RET |1 RET Sx'), but 1) even/odd zones due to rotated kernel
2) eigenvalues sometimes wrong because we don't mix in circular
component. fixed waves (wasn't initializing because before it wasn't
static so it was sharing values with shade).  added color, shape, and
mood organs.  defined a-n on the mood organ.  (on the mac: fixed colors
(had exchanged blue and green channels).  fixed keyboard handling (use
GetOSEvent), added handling of command-q.  moved suck files into
subdirectory.  hides cursor. R is 32 bits not just 16.)

release 1.7, as of Jan 30 1996
added reaction diffusion textures, as per
http://www.ccsf.caltech.edu/ismap/image.html.  lots more to do with
these.  moved RD to 'd', various updates to manual.txt.

release 1.6, as of Jan 25 1996
merged in version from laptop (exchanged rotor shapes `rectangular'
and `vertical'.  added 'H' (horizontal) and 'J' (vertical) double heat
buffer (though i think they're broken), added to auto_mode.)  mac
version flushes events before it exits.  if not in emacs, then use CR
to keep ticks on one line.  added delay with feedback control to keep
frames per second near 15.  moved cmap pulse code into procedures.

release 1.5, as of Jan 15 1996
improved Mac port: it basically works, though the keyboard handling is
a mess.  it's based on polling so a quick key press-release is missed.
i'm not sure how to get events without handing over control to other
threads.  the mac version can only load ppm files, and for some reason
i can't load files in a subdirectory.  various bug fixes.  added a
bunch of new colormaps from paintings.  added image2cmap.c, which
computes the colormaps.

release 1.4, as of Jan 10 1996
flipped OpenGL version right-side-up, boosted pixel replication to
3x3.  note that some implementations of OpenGL perform terribly on
pixel replication (eg a GU1-Extreme); in this situation try setting
pix_rep to 1.  added flush to title screen display, added mac port,
replaced missing title.gif file.

release 1.3, as of Dec 22 1995
added ports to X windows and OpenGL (i was hoping it would be faster,
but instead it's slower.  still upside down anyway).  fixed bug in
slip (it was writing off the edge of the fb).  until my laptop
recovers a bunch of other changes are lost on its disk.  in the
meantime i reimplemented 'S' which toggles smooth/plain cmaps, cuz i
like it so much.

release 1.2, as of 
added manual.txt.  sometimes screen activity stops but still accepts
key input, has the rule gone bad???.  reduced chance of using
image_to_heat() in slip automode by 10x.  added symmetric life from
torben, added fredkin rule and special filling for it (controlled by
brain parameter 'v'). these still need some work.  adjusted edge
conditions for all the acidlife rules.  doesn't overwrite files in
dribble directory (write_fb_ppm).  displays any titleN.gif files (N =
0,1,2,...) on startup with keypress to go to next.  added pop_back to
automode.  added 'D' permute colormap by bits, and incorporated into
automode.  added angular slugs (shade.c). added ticking and fps
(frames per second) printout.

release 1.1, as of Aug 14 1995
adjusted how overdrive and rule_lock work in automode.  ' ' disables
auto_mode.  added 'B' fade to black.  added quick startup option.
adjusted bsize for the rotor (reduced the high end).  fixed clearing
buffers with driving image.

release 1.0, as of Jul 14 1995
auto_rule makes sure it starts out well.  on transition to
rule_rug_image, clear the buffers with the driving image, too often we
have noise, which looks bad.

release 0.20, as of Jul 12 1995
fixed bad scanline bug in multi_rug.  redid many of the kbd controls
so that shift and control are not needed for common controls, more
context sensitive keys in general.  zxcvbn cause events, asdfghjkl;'
switch modes, qwertyuiop[]| pick a parameter to vary, ,.1234567890 and
return vary the parameter.  if you repeated hit a parameter key, it
varies that parameter.  added lissajous and oscilloscope-oid to rotor,
added pens to rotor (draws bsize rects instead of just dots), added
image sequences, rearranged all sorts of image controls, wrote some
sequences.  wrote manual.txt, explaining the ui.  fixed bug in initial
parameters (wasn't setting speed_base).

release 0.19, as of Jun 18 1995
added more images, cropped and tuned existing images.  tracks variance
of pixels in fb, if it's too low, then randomized the fb.  improved
next_contrasting_color, seems ok now.  in auto-mode, reduced chance of
filling.  uses a checkerboard if no images are found in the suck dir.
in rotorug, drift-mode is more likely to be chosen.  added mode-lock
on 'L'.  added rug_multi mode.  more images in the suck dir.  added
title page (need a better one though).  fixed %0 bug in
image_random_tile().  added optional underflow to shade mode.  removed
night-blue-sky and mauve-splat cmaps (too often result in
near-blackness).  split off fast.c from bomb.c, and disabled
optimization of bomb.c.  added blitting image tiles into the heat on
'^I' and into the game board on '^U', '^Y' cycles auto-blit rate.
added speed beat (rate on '}', size on '{').  reads cmaps at runtime.
wrote image2cmap.  fixed uninitialized driver plane bug.

release 0.18, as of May 25 1995
quick-flip auto-mode, redid interpretation of driving function in
brain mode to include asymmetric diffusion kernels, added fuse mode
(still needs work), fixed bug in writing ppm files.  when leaving
modes that operate directly on the fb (eg slip, fuse), pixel values
are interpreted as heat.  bsize made variable.

release 0.17, as of Apr 25 1995
removed contents of dribble directory. added more auto-mode features.
added rhythmic flames.


release 0.16, as of Apr 21 1995
added 'C' (invert driver) '^B' (load random image) 'Z' (combined zx
and ^B), all basically for rug_image mode.  included a bunch of
images. added 'X' = zcm for flame/rotor.  enabled `bent' flame
variation (?).  reads gif files (code taken from xli, see copyright
notices below).  '=' writes current screen into dribble
directory. brain chooses random shift bits, and includes PHASE_ZAP
code to prevent strobing (somewhat effective).  'P' modifies these
shift bits, should build a different sub_brain_table for different
shift bits.  added 'E', 'W', 'R' colormap pulsers.  added 'T' colormap
brightener. added 'Q' which enters auto-mode immediately (instead of
waiting for the time delay), made auto-mode fancier.  added some
variations to slip. '^Q' speeds up auto-mode.  added many gif files to
suck directory.

release 0.15, as of Feb 16 1995
put drift_mode into distrib now that flame is fixed.  removed
mode_life since it was never implemented and was causing a bug.  added
terrible hacks so that random mode can get display images.  smoothed
over transitions.  loading of files less hacked, holds 5 of them in
memory for fast access, 'B' rotates through them.  code really getting
cruddy.  moved rule_rug_image and support into image_rule.c.  included
a ppm file in the release.

release 0.14, as of Feb 15 1995
'R' pulse_gparam (not quite right, i think), suck.ppm replaced by
suck/$(p1).ppm (p1 still under 'o').  new drift modes for flames:
rotation, and none (ie the flame stays still).  bug fix from
bcsaller@mailbox.syr.edu (call vga_init()).  flames finally fixed by
resetting point if it strays outside 1e10.  reads library of flames in
at startup, 'M' sets to p1.

release 0.13, as of Feb 10 1995
'z' no longer resets flame coefs, 'm' does instead.  smooth colormap
transition (though the whole cmap is reset every frame producing
an icky video artifact on my display) from nix.  image mode on 'S'
(reads from suck.ppm on '/') and wispy waves on 'A' from nix.  both of
these are still quite rough.

release 0.12, as of Feb  7 1995
mostly fixed flames.  nice!

release 0.11, as of Feb  7 1995
used most of the brain parameters (p key), handles changing symmetry
more smoothly, brain remaps heat, new compiler flags, flame option in
rotor code (v key) (though still somewhat broken), pulsing (b
key). generalized brain some more (see XXY), though still not
used. twiddled constants, batched flame movement, added drift controls
(\[, - keys).

release 0.10, as of Jan 23 1995
memory maps frame buffer (still usually ignores width/height though),
renamed the whole thing `bomb'.  redid the makefile.

release 0.9, as of Jan 19 1995
kbd commands redone, new rules brain (lots of unused parameters here)
and shade, broke rules into separate files

release 0.8, as of Jan 13 1995
more kbd commands (including simple scripting), bugs fixed

release 0.7, as of Jan 10 1995
keyboard input, life/rug variants are mirrored

release 0.6, as of Jan  3 1995

-----------------------

the following is for gif.h and gif.c

/****
  Copyright 1989, 1990 Kirk L. Johnson

  Permission to use, copy, modify, distribute, and sell this
  software and its documentation for any purpose is hereby granted
  without fee, provided that the above copyright notice appear in
  all copies and that both that copyright notice and this
  permission notice appear in supporting documentation. The
  author makes no representations about the suitability of this
  software for any purpose. It is provided "as is" without express
  or implied warranty.

  THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT
  OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
  NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
****/

the following is for xli-image.h

/*
 * Copyright 1989, 1993 Jim Frost
 *
 * Permission to use, copy, modify, distribute, and sell this software
 * and its documentation for any purpose is hereby granted without fee,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear
 * in supporting documentation.  The author makes no representations
 * about the suitability of this software for any purpose.  It is
 * provided "as is" without express or implied warranty.
 *
 * THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
 * USE OR PERFORMANCE OF THIS SOFTWARE.
 */
