数字雨

#include <graphics.h>
#include <math.h>
#include <conio.h>
#include <time.h>
struct f{
	int x;
	int y;
	char ch;
	int speed;
};
int main() {
    initgraph(1024, 600);
    srand(time(NULL));
    f a[300];
    for(int i=0;i<300;i++){
    	a[i].x=rand()%1024;
    	a[i].y=-(rand()%600);
    	a[i].ch=rand()%93+33;
    	a[i].speed=2+rand()%5;
	}
    LOGFONT f;
    gettextstyle(&f);
    f.lfHeight=24;
    _tcscpy(f.lfFaceName, _T("爱点萌娃体"));
    settextstyle(&f);
	BeginBatchDraw();
	while(!_kbhit()){
		cleardevice();
		for(int i=0;i<300;i++){
			settextcolor(RGB(0,100+rand()%120,0));
			TCHAR str[2]={(TCHAR)a[i].ch,0};
            outtextxy(a[i].x, a[i].y, str);
            a[i].y+=a[i].speed;
            if(a[i].y>600){
            	a[i].y=-20;
            	a[i].x=rand()%1024;
			}
			if(rand()%10>7){
				settextcolor(RGB(0,100,0));
				for(int j=5;j<=30;j+=5){
					outtextxy(a[i].x,a[i].y-j,str);
					
				}
			}
		}
		setfillcolor(RGB(0,50,0));
    	solidrectangle(0,500,1024,600);
		FlushBatchDraw();
		Sleep(20);
	}
	
	EndBatchDraw();
    closegraph();
    return 0;
}

  

posted @ 2025-05-03 15:42  陈若麟  阅读(6)  评论(0)    收藏  举报