#include <graphics.h>
#include <cstdlib>
#include <conio.h>
#include <ctime>
int col[15]={0xA80000,0x00A800,0xA8A800,0x0000A8,0xA800A8,0x0054A8,0xA8A8A8,0x545454,0xFC5454,0x54FC54,0xFCFC54,0x5454FC,0xFC54FC,0x54FCFC,0xFCFCFC};
typedef struct SnowPOINT
{
int x;
int y;
int speed;
int style;
}SP,*pSP;
SP Poi[10];
int SnowPoint_R=2;
void Init();
void Blur(DWORD *IBuffer);
void Draw();
void DrawSnowPoint();
void Init()
{
setbkcolor(BLACK);
setcolor(WHITE);
cleardevice();
srand(unsigned int(time(NULL)));
for(int i=0;i<10;i++)
{
Poi[i].x=rand()%600+15;
Poi[i].y=-(rand()%450);
Poi[i].speed=rand()%4+1;
Poi[i].style=col[rand()%14];
}
}
void Blur(DWORD *pMem)
{
for(int i = 640*2; i < 640 * 478; i++)
{
pMem[i] = RGB(
(GetRValue(pMem[i]) + GetRValue(pMem[i - 640]) + GetRValue(pMem[i - 1]) + GetRValue(pMem[i + 1]) + GetRValue(pMem[i + 640])+GetRValue(pMem[i+640*2])/*+GetRValue(pMem[i+2])+GetRValue(pMem[i-2])*/+GetRValue(pMem[i-640*2])) / 7,
(GetGValue(pMem[i]) + GetGValue(pMem[i - 640]) + GetGValue(pMem[i - 1]) + GetGValue(pMem[i + 1]) + GetGValue(pMem[i + 640])+GetGValue(pMem[i+640*2])/*+GetGValue(pMem[i+2])+GetGValue(pMem[i-2])*/+GetGValue(pMem[i-640*2])) / 7,
(GetBValue(pMem[i]) + GetBValue(pMem[i - 640]) + GetBValue(pMem[i - 1]) + GetBValue(pMem[i + 1]) + GetBValue(pMem[i + 640])+GetBValue(pMem[i+640*2])/*+GetBValue(pMem[i+2])+GetBValue(pMem[i-2])*/+GetBValue(pMem[i-640*2])) / 7);
}
for(int x=0;x<640;x++)
{
pMem[x]=BGR(RGB(255,255,255));
pMem[640*479+x]=BGR(RGB(255,255,255));
pMem[640*478+x]=BGR(RGB(255,255,255));
pMem[640+x]=BGR(RGB(255,255,255));
}
}
void Draw()
{
DrawSnowPoint();
for(int i=0;i<10;i++)
{
if((Poi[i].y>=480))
{
Poi[i].y=0;
Poi[i].x=rand()%630;
Poi[i].style=col[rand()%14];
}
}
for(int y=0;y<10;y++)
{
Poi[y].y+=Poi[y].speed;
}
}
void DrawSnowPoint()
{
for(int i=0;i<10;i++)
{
setfillstyle(Poi[i].style);
circle(Poi[i].x,Poi[i].y,SnowPoint_R);
fillcircle(Poi[i].x,Poi[i].y,SnowPoint_R);
}
}
int main()
{
initgraph(640,480);
Init();
HWND hWnd=GetHWnd();
SetWindowText(hWnd,"七彩雨");
DWORD *Buff=GetImageBuffer();
BeginBatchDraw();
while(!kbhit())
{
Draw();
Blur(Buff);
FlushBatchDraw();
}
EndBatchDraw();
closegraph();
return 0;
}