Diffusion Chamber, by Michael Martin

This is a simple demo that simulates two liquids diffusing.  Each block wanders
about randomly and, while the blue and green blocks start out separated, they
mix fairly rapidly.  (Really, this is more of the surface of a torus than a
box; blocks can wrap around any edge of the container.)

It was inspired by a description by A.K. Dewdney from his old Scientific
American column, "Computer Recreations."  You may find it in his collection
"The Magic Machine", in the Chapter 23, "Balls in Boxes."  He calls the program
"BLEND" and describes it on pp. 263-265.

Programmatically, this code is interesting because it splits the work up
between VBLANK phases and non-VBLANK phases.  Finding a block to move can take
arbitrary amounts of time (it generates random motions until it finds a legal
one), so it cannot be done in VBLANK.  So, the VBLANK routine and the main
program pass cues back and forth, including a code pointer to instruct the
VBLANK routine what to do.

Source is in diffuse.p65, and specifies everything, including the graphics.  It
will assemble under P65 version 1.1 or later.  To acquire a copy of P65, go to
http://hkn.berkeley.edu/~mcmartin/P65/index.html and look through the
downloads.

Enjoy!
Michael Martin
16 April 2002
