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


=================================-
Forward
==============================-
Hi! If your reading this text then I guess you liked the first tutorial or
havn't yet seen the first tutorial. Anyways, if you read the first tutorial,
you will know what sorta person these tutorials are for. WARNING: This
tutorial is quite trickey! If you don't understand, don't worry too much. I
am going to move on to something a little more simple next week.
        This second tutorial is about cross fading, another interesting way
of changing from one image to another. This, is a good looking effect that
I'm sure someone out there will find a use for.

=================================-
What Is Cross Fading
==============================-

Cross Fading is where one image fades to another. This is not like fading
the screen out and fading it back with the new image, this is fading one
image "through" another.

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

1. You need two 16 colour images that you want to fade into each other.
The maximum number of colours is 16 because if you think about it, there are
(16 * 16) = 256 possable combinations of colours which could overlap.

2. You need to then store the palette of both images into two arrays. Lets
call them palimage1 and palimage2.
        
3. You need to build a colour chart. This is a table with a unique colour
allocated to every possible pixel colour combination on the two 16 colour
images. Here is the code to build one:

for c1% = 0 to 15
 for c2% = 0 to 15
  colourchart (c1%, c2%) = crosscolour%
  crosscolour% = crosscolour% + 1
 next
next

This code should not be hard to understand.

4. You need to combine, using your colour chart, the two images. This is where
DirectQB comes in handy as it allows us to easily read any part of the two
images. This is the code to do it:

for y% = 0 to 199
 for x% = 0 to 319
  colour1% = dqbpoint 1, x%, y%
  colour2% = dqbpoint 2, x%, y%
  combinedcolour% = colourchart (colour1%, colour2%)
  dqbpset video, x%, y%, combinedcolour%
 next
next

5. Now you need to build your starting and ending palettes for the combined
image. Note, palimage1 is the 16 colour palette of the first image, palimage2
being the second.

for c1% = 0 to 16
 for c2% = 0 to 16
  palette1%(colourchart(c1%, c2%), 1) = palimage1(c1%, 1)       'Red
  palette1%(colourchart(c1%, c2%), 2) = palimage1(c1%, 2)       'Green
  palette1%(colourchart(c1%, c2%), 3) = palimage1(c1%, 3)       'Blue
  palette2%(colourchart(c1%, c2%), 1) = palimage2(c2%, 1)       'Red
  palette2%(colourchart(c1%, c2%), 2) = palimage2(c2%, 2)       'Green
  palette2%(colourchart(c1%, c2%), 3) = palimage2(c2%, 3)       'Blue
 next
next

This code should be self-explanitary if you read it through.

6. Now it is just a simple case of smoothly moving from one palette to the
other. You can do this by working out the difference between each of the
R/G/B's and dividing each of the values by for example 64, if you then add the
results to each R/G/B 64 times, voila, you have reached palette2. Show this
on the screen and you have a nice cross fade. You will need another array to
store the values you will be adding to the red, green and blue of each image.

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

This is not an easy effect to code. Try looking at the example. Once again, it
uses DirectQB, so you will need to load it with QB /L DQB and once again, for
those of you without QB 4.5, there is an EXE file included for you to have a
look at. I'm probably going to start on a few more simple consepts such as
3D starfields and maybe free directional 3D starfields.

Terminator_Z / CRiTiCAL MASS
email to: shadow@georgeg.force9.co.uk
Check out our groups homepage: http://critical.hypermart.net
Check out FoX, my upcomming game!
