字母雨

#include <graphics.h>
#include <conio.h>
#include <bits/stdc++.h>
#include <ctime>
struct a1{
	int x,y,speed;
	char c;
};
a1 n[300];
int main()
{
	initgraph(1024,640);
	srand(time(0));

	for(int i=0;i<300;i++){
		n[i].x=rand()%1024;
		n[i].y= -(rand()%640);
		n[i].c= rand()%93+33;
		n[i].speed=rand()%5+2;
	}
	LOGFONT f;
	gettextstyle(&f);
	f.lfHeight = 24;					
	_tcscpy(f.lfFaceName, _T("楷体")); 
	settextstyle(&f);	
	BeginBatchDraw();				
	while(true){
		cleardevice();
	
		for(int i=0;i<300;i++){
			settextcolor(RGB(0,100+rand()%156,0));
			outtextxy(n[i].x,n[i].y,n[i].c);
			n[i].y+=n[i].speed;
			
			if(n[i].y>640){
				n[i].y-=20;
				n[i].y= -(rand()%640);
			}
				
			if(rand()%10>7){
			settextcolor(RGB(0,50,0));
			outtextxy(n[i].x,n[i].y-20,n[i].c);
				}

			}
	FlushBatchDraw();
	Sleep(20);
		
	}

	
	_getch();
	closegraph();
	return 0;
}

  

posted @ 2025-05-03 15:47  付书恒  阅读(19)  评论(0)    收藏  举报