Make your own free website on Tripod.com

Snow.

Prev || Home

bar.gif (11170 bytes)

/*
** Simple snow effect. Change the col1/col2 variables to reflect
** changed color of the snow. Compile with DJGPP C. Porting to
** other C compilers shouldn't be a problem
**
** Note: This snow effect uses two colors for better effect.
** A single color can be used for simplicity
**
** Routine by KR Ranjith (ranjithk@crosswinds.net)
** Date: 7/29/00
*/


#include <dos.h> /* int386 */
#include <pc.h> /* inportb */
#include <stdlib.h> /* malloc, rand, srand */
#include <time.h> /* time */
#include <sys/nearptr.h> /* __djgpp_nearptr_enable/disable */

int main()
{
unsigned char* scr;
unsigned char* vscr;
union REGS s;
int t;
const int col1=78, col2=77;
int script_frames = 100;

__djgpp_nearptr_enable();

    scr = __djgpp_conventional_base + (unsigned char*)0xA0000;

/* X video mode */
s.w.ax = 0x13;
int386(0x10,&s,&s);

vscr = (unsigned char*) malloc( 320*200 );

if( !vscr )
{
    printf("Not enough memory");
    return(0);
}

memset(vscr, 0, 320*200 );

srand( time(NULL) );

while( !kbhit() )
{

/* The top line */

for(t=0; t<320; t++)
*(vscr+t)= (rand()%100)==99 ? ((rand()%30)>25 ? col1: col2 ): 0;

for(t=320*200-322; t >= 0; t-- )
{

/* If it's edge of the screen, skip processing and blank pixel */

if( t%320==0 || t%320==1 )
{
*(vscr+t)=0;
continue;
}
   
   

if( *(vscr+t) ) /* colored ? */
{
if( rand()%2 ) /* get a random side */
{
/* left side */

if( *(vscr+t+319) )
{
if( *(vscr+t+321) )
                    {
if( *(vscr+t+320)==0 )
{
*(vscr+t+320) = rand()%2 ? col1: col2;
*(vscr+t)=0;
}
}
        else
{
*(vscr+t+319) = rand()%2 ? col1: col2;
*(vscr+t) = 0;
}
}
else
{
*(vscr+t+319) = rand()%2 ? col1: col2;
*(vscr+t) = 0;
}
}
else
{
/* right side */

if( *(vscr+t+321) )
{
if( *(vscr+t+319) )
{
if( *(vscr+t+320)==0 )
{
*(vscr+t+320) = rand()%2 ? col1: col2;
*(vscr+t)=0;
}
}
else
{
*(vscr+t+319) = rand()%2 ? col1: col2;
*(vscr+t) = 0;
}
}
else
{
*(vscr+t+321) = rand()%2 ? col1: col2;
*(vscr+t) = 0;
}

}
}

}

    /* retrace sync */
    while( inportb(0x3Da) & 0x8 );
    while( ! (inportb(0x3Da) & 0x8) );

/* for dots, not so great speed improvement, yet... */
memcpy(scr,vscr,320*200);

}

getch();

/* Text mode */
s.w.ax = 0x3;
int386(0x10, &s,&s);

free(vscr);

__djgpp_nearptr_disable();

return(0);
}

bar.gif (11170 bytes)