THE SPARKLE EFFECT

Enclosed files: sparkle.c   (the source)
                sparkle.mak (makefile for MS Visual C++ 4.0)
                sparkle.rc  (script for resource compiler)
                sparkle.bmp (frames for the animation)
                SPARKLE.EXE (compiled program)

SOME NOTES
This program was coded using the windows programming template derived from
the book "Programming Windows 95" by Charles Petzold and Paul Yao.
I own various books about windows programming, but this is the only one
that refers only to plain C functions and API calls. This could be is some
way an old programming mood (at least compared with C++ Builder by Borland,
or the MFC) but, by me, is the only way to completely understand what is
going on under the surface. (...and this is one of the causes we are so
easily cracking modern windoze programs).
I have successfully compiled this using Microsoft Visual C++ 4.0 (this is
a good tool used on command line, and contains a lot of reference - and
now, in 1998 this is so old you can buy it for almost nothing).

How the program works:
we are going to reproduce the sparkle effect we can see in BrainsBreaker 2.1
First of all we want to reverse programmer's work, to see how him did it.
So i placed a BPX BitBlt and then closed the prog. In about 2 minutes i
was looking at the sparkle routine. (tracing back from the breakpoint to
routine entry). When i get an address to start browsing, i jumped to my
dead listing of the BBRK32.EXE (produced for the game cracking).
The sparkle routine is between address 42EACF and 42EADD. We can see here
some calls to various routines. But this go without saying. The interesting
part is how the star is drawn. And this is done using 2 calls to Ellipse
and 4 calls to LineTo. (offset 42F0F8, 42F120, 42F191, 42F1C5, 42F1FB,
42F240). The program draws in a memory Device Context (DC) and the moves
it to video memory using a BitBlt call. (This is in some way similar to
old dos double buffering). This produces the nice sparkle effect.

How i did it:
the entire effect is contained in an area of about 15x25 pixels. So, i
decided to implement the effect in a different way, 'cause at this size 
we can use a sort of animation. Moreover, even if we are crackers, i 
believe it is not correct to simply copy an effect by another programmer.
We can study how it works, we can reverse the hell out of it, but
i think (hey, this is only my opinion) copying it is not the right thing.
(at least with a graphic effect...)
What i did is to create a simple program to load a bitmap from its resources
and bring from this bitmap the frames used for our animation.
The process is particularly fast for a small area like this one (even on
my 486/33).
I used Borland Resource Workshop to create images, and Paint Shop Pro to
assemble them in a unique bitmap. Then the BitBlt functions accepts 
image coordinates to decide from where to copy data, and so we only have
to select the right frame.
This routine is basically the same as old system of doing cartoons, a lot
of drawings that in sequence appears as an animation.
I know this requires less coding than the original routine, but i think
this could be understood more easily, opens your fantasy to others effects
(what do you think of an ORC image morphing in HCU?), and so i have coded
something totally on my way (the ultimate challenge in the strainer says:
"reproduce the graphic effect" and this is what i did!)
NOTE: the effect is slower than the original (at least on my machine), but
this is due to the different number of frames in the animation. Original
is about 15 15x25 frames, my effect is 21 20x30 frames. Anyway you could
change the number of frames and their size if you want !!!

Comments on code:
program uses normal window creation attributes. We have added to the standard
template (window registration and message loop) a call to load the bitmap
from resources, and to set a timer. This timer (i've set it to 100 millisec -
change it if animation if too fast in your super Pentium II) gives us the
right time to change from a frame to the other. Windoze respond to a timer
setting generating a WM_TIMER message with defined time resolution.
And responding to this message we obtain the animation.
Program window contains no particular icon, to keep coding as clean as
possible. Window can be resized, and the animation continues in the new
client area.
										
											bye, Mad 1-VI-1998
                                        bye, Mad - 1/VI/1998
