发布网友 发布时间:2022-05-11 16:02
共1个回答
热心网友 时间:2023-10-14 18:01
# include <dos.h> # include <time.h> # include <conio.h> # include <stdio.h> # include <stdlib.h> # include <graphics.h> struct Snow //雪的结构体 { int x; int y; int size; int speed; }snow[200]; int snownum=0; //初始化雪花数量 void *save1,*save2,*save3,*save4; //储存各个元素 void Copy() //储存元素主程序 { setcolor(0); setfillstyle(1,15); fillellipse(200,200,2,2); //大雪花 fillellipse(200,210,2,1); //中雪花 fillellipse(210,200,1,1); //小雪花 save1=malloc(imagesize(196,196,204,204)); //储存大雪花 save2=malloc(imagesize(196,196,204,204)); //储存中雪花 save3=malloc(imagesize(196,196,204,204)); //储存小雪花 save4=malloc(imagesize(196,196,204,204)); //储存背景色的图块 getimage(196,196,204,204,save1); getimage(196,208,204,212,save2); getimage(208,198,212,202,save3); getimage(96,96,104,104,save4); cleardevice(); } void DrawSnow() //下雪主程序 { int i; randomize(); while(!kbhit()) { if(snownum!=120) //初始设置雪花属性 { snow[snownum].speed=2+random(3); snow[snownum].x=20+random(600); snow[snownum].y=0; snow[snownum].size=random(3); snownum++; } for(i=0;i<snownum;i++) putimage(snow[i].x,snow[i].y,save4,0); for(i=0;i<snownum;i++) { snow[i].y+=snow[i].speed; switch(snow[i].size) //选择下落的雪花大小 {case 0: putimage(snow[i].x,snow[i].y,save1,0); break; case 1: putimage(snow[i].x,snow[i].y,save2,0); break; case 2: putimage(snow[i].x,snow[i].y,save3,0); break; } if(snow[i].y>500) //雪花落下后重新计算雪花属性 { snow[i].speed=3+random(3); snow[i].x=20+random(600); snow[i].y=0; snow[i].size=random(3); } } delay(5000); } } void main() {int driver=DETECT,mode; initgraph(&driver,&mode,""); Copy(); DrawSnow(); }