------------------------------------------------------------------------------
                     _|_  .    *           +    .
         .            :_______________________________        +
                    _=|TERMINATOR_Z's QBasic Tutorials|=_ .
              *     ~=|_________CRiTiCAL_MASS_________|=~          *
                         .                   +     *       
             .       +                .                     .
Issue 1_______________________________________________________________________


=================================-
Forward
==============================-
Hi! and welcome to the first in a series of QBasic tutorials. Note, these
tutorials are not aimed at beginners, they are aimed at novice to advanced
programmers with some basic knowledge of math. Anyways, I hope you enjoy
reading is as much as I enjoyed writing it. If you do like it and want to see
it continued, email me and tell me what you think of the tutorials, how I can
improve them and what topics you would like to see covered in future issues.
This first tutorial is about a simple effect known as pixel morphing.


=================================-
What Is Pixel Morphing
==============================-

Pixel morphing is where different pixels at different positions move to new
positions. These positions are often in the form of images and so when they
move to their new positions, it gives the effect of one image morphing into
another. This is a very simple effect but it looks really good.


=================================-
So, How Is It Done?
==============================-

Firstly, you must have both of your images loaded into two different arrays.
Chances are that one of your two images will have more pixels or less pixels
than the other so on the smaller image, you must take the required amount of
pixels from the head (start) of the array and copy them onto the tail (end)
like so:

Image 1:                           If the other image is more than twice the
1  2  3  4  5  6  7  8  9          size, don't worry, just make your routine
                                   for copying the bytes move one at a time,
Image 2:                           stepping through the array for the 
  ___________________              required amount of pixels. When it has been
[1  2]  3  4  5  6  [1  2]         through the array once, it will just find
                                   the data it has already copied and continue
                                   copying it to the end of the array, this is
                                   fine...

Right, so now you have two arrays of pixels both the same size, you can worry
about gradually moving one to the other. A simple approach would be to say
that for example, if its Y destination is greater than its current Y position
then decrement its current Y position. This would look a little crappy though
as the pixel would only ever move at set angles:

Source X \
           \                             
             \                             
               \                             
                 -------------------------------- X Destination

This would not look particularly nice now would it? Another problem with this
method is that the pixels would take different times to reach their
destination whereas we want them all to reach their destination all at the
same time.

Source X ------------X Destination
Source X ---------------------------------X Destination


To get all of the pixels reaching their destination at the same time,
we define a value which relates to the number of frames of the morphing
animation we want before the pixels have to have reached their destination and
voila, however many frames later, all pixels, no matter how near or far from
their destination they were, have reached their destination. Read on to see
how this is done...

The next part is getting all the pixels to move in straight lines. This is
not as hard as you might think...

Lets assume that (x1, y1) is where our pixel is and (x2, y2) is where it wants
to be.

(x2-x1) = Distance between the 2 points on the X axis
(y2-y1) = Distance between the 2 points on the Y axis
The number of frames we want in our animation is 64

Addx = (x2 - x1) / 64
Addy = (y2 - y1) / 64

And guess what, if you add Addx to X1 64 times you will have X2 and the same
as if you add Addy to Y1 64 times, you will have reached Y2. When we plot
this on the screen, you will have a pixel moving in a straight line which
takes 64 steps to reach its destination!

You will need to define a third array, the size of one of the first two
(remember, they are both the same size!) which would have four
dimensions, one for the current X position of the pixel, one for the
current Y position, one for the value that you will be adding to your
X position each time and the final one for the value that you will be
adding to the Y each time. You must copy the first image to the third array
and calculate what you will be adding to the X and Y values from the first
and second image arrays.


=================================-
In Closing
==============================-

Don't worry if this tutorial is not at first clear, read it a few times, read
the code included, I'm sure eventually it will all become clear.


=================================-
The Example Program
==============================-

The example program included uses DirectQB from Angelo Motello as it is faster
than the QBasic instructions PSET, etc. It also allows for the use of video
pages as well which totally kills all flicker! 
Because of this, you will need to link DirectQB to use the example program.
To do this, you must do the following:

In the directory you have placed the .ZIP file, type:
C:\QB\QB /L DQB

C:\QB being the directory in which QB 4.xx is loacted, change to sute your
machine.

If you do not have QB 4, I have included an EXE file so you can see what I
am talking about.
