#include #include #include #include #include #include void Init_Video(char Drctry[50]); void Flip(void); void Storm(void); void Rain(int nD); char *pMsg = "Storm!... Lightning!..."; int nDrps = 700, Ltng = 1; struct POINT { int x,y,c; }; struct POINT pix[700]; int xmax, ymax, cmax; int main() { int i; randomize(); Init_Video("d:\\tc\\bgi"); xmax = getmaxx(); ymax = getmaxy(); cmax = getmaxcolor(); for (i=0; i xmax || pix[i].x < 0) { pix[i].x = random(xmax); pix[i].y = 0; switch (rand()%4) { case 0: pix[i].c = 8; break; case 1: pix[i].c = 7; break; case 2: pix[i].c = 15; break; default: pix[i].c = random(cmax); } } if (pix[i].y > ymax || pix[i].y < 0) { pix[i].x = random(xmax); pix[i].y = 0; switch (rand()%4) { case 0: pix[i].c = 8; break; case 1: pix[i].c = 7; break; case 2: pix[i].c = 15; break; default: pix[i].c = random(cmax); } } switch (pix[i].c) { case 8: pix[i].y = pix[i].y + random(2); pix[i].x = pix[i].x + random(2); putpixel(pix[i].x, pix[i].y, pix[i].c); break; case 7: pix[i].y = pix[i].y + random(2) + 1; pix[i].x = pix[i].x + random(2); putpixel(pix[i].x, pix[i].y, pix[i].c); //break; case 15: pix[i].y = pix[i].y + random(2) + 2; pix[i].x = pix[i].x + random(2); putpixel(pix[i].x, pix[i].y, pix[i].c); //break; default: pix[i].y = pix[i].y + random(2) + 1; pix[i].x = pix[i].x + random(2) - 1; putpixel(pix[i].x, pix[i].y, pix[i].c); } } } void Storm() { char c; Flip(); while ((c=getch())=='m' || c=='l') { if (c=='m') { printf("Enter Message:"); gets(pMsg); c=' '; Flip(); } if (c=='l') { Ltng = Ltng * -1; c=' '; setbkcolor(BLACK); Flip(); } } } void Init_Video(char Drctry[50]) { /* select a driver and mode that supports multiple pages. */ int gdriver = VGA, gmode = VGAMED, errorcode; /* initialize graphics and local variables */ initgraph(&gdriver, &gmode, Drctry); /* read result of initialization */ errorcode = graphresult(); if (errorcode != grOk) /* an error occurred */ { printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:"); getch(); exit(1); /* terminate with an error code */ } } void Flip() { int i, j, k; setvisualpage(0); j = xmax; while (!kbhit()) { settextstyle(random(10), HORIZ_DIR, random(12)); setcolor(random(cmax)); k = random(ymax); while (j>-textwidth(pMsg) && !kbhit()) { for (i=0; i<2; ++i) { setactivepage(1 - i); cleardevice(); outtextxy(j, 100, pMsg); Rain(nDrps); if (Ltng==1) { if (random(20)==13) k = 3; switch(k) { case 3: setbkcolor(WHITE); //delay(25); break; case 2: setbkcolor(LIGHTGRAY); //delay(25); break; case 1: setbkcolor(DARKGRAY); //delay(25); break; default: setbkcolor(BLACK); } k--; } j--; setvisualpage(i); //delay(500); } } j = xmax; } }