SPARKY - Pixelate Particle Effect Competition, April 2001
=========================================================

Ben Davis
ben@vjpoole.freeserve.co.uk
http://bdavis.netfirms.com/


This is my humble entry into the Pixelate Particle Effect
Competition, April 2001. It uses a particle system, along
with a warp matrix, to create some stylised sparks and
smoke.

Notice that this program is not just called 'particle',
since you will probably want to install it in a different
directory from all the other entries! *wink wink, people*

The source code is modular (hopefully!), so you should be
able to use it in your own programs with little effort.
Apologies for the lack of comments.

Please credit me if you use this effect in your programs.

The following website was an invaluable resource while
writing this program:

http://freespace.virgin.net/hugo.elias/


Compilation
-----------

A DOS executable is provided. If you wish to compile the
program on a different platform, just compile all the .c
files and link them with Allegro. If you do not know what
those instructions mean, just use the DOS version.


How it works
------------

All particles have position and velocity. Particles are
initiated in the centre of the screen with a random
velocity, chosen in terms of radius and angle to avoid
squareness.

To propagate the particles, the velocity is added to the
position each frame.

In order to achieve the swirling effect, we use a warp
matrix. This is an array of points mapped on to the
screen. At each point we store a displacement and a
velocity. These are both vectors, so they consist of two
values, x and y.

The warp matrix is propagated by adding the velocity to
the displacement at each point. In addition, we pretend
each point is attached to its neighbouring points by
springs, and adjust the velocity accordingly. We do not
model this accurately, as force is only applied in the
natural direction of each spring - but an accurate model
is not necessary for this application.

Every frame, each particle is accelerated by the warp
matrix. The particle's position is mapped on to the
matrix, and the displacement of the corresponding point
in the matrix is used as an acceleration vector for the
particle. In fact the program will always interpolate
between points, since the particle is unlikely to lie
directly on top of any one point in the warp matrix.

As soon as a particle leaves the screen, it is deleted.

Particles are drawn as lines from their position last
frame to their current position, giving a very cheap
motion blur effect.

In between frames, the whole image is blurred and
smudged opposite to the direction of the warp matrix at
each point. This means the sparks go in a direction
opposite to the smoke, so the sparks seem to propel
themselves by means of smoke. The new sparks are drawn
on top of the blurred image.

The blurring function relies on the source bitmap being
larger than the destination bitmap. This means that no
comparisons are necessary in the inner loop to avoid
overrunning the edges of the bitmap; we can simply read
from the black areas. Comparisons would be expensive in
terms of speed.

Note that the function warpblur() is still by far the
slowest part of this program. I strongly recommend you
do not try to run this program in high resolution.

Furthermore, parts of this program are written
specifically for 8-bit graphics. Increasing the colour
depth would require major rewriting of parts of the
program, the colour gradient would be harder to achieve,
and the effect would probably be too slow.

Anyway, enough analysis. Enjoy the effect, and feel free
to use it in your own programs, provided you credit me.


Ben Davis
ben@vjpoole.freeserve.co.uk
http://bdavis.netfirms.com/
