#include<stdio.h>
#include<stdlib.h>
#include<graphics.h>
#include<math.h>
#define NUM 10
#define NUM_OF_XING 600
struct xing
{
int x;
int y;
int color;
};
struct star
{
int x;
int y;
int end;
int color;
struct xing* son;
}*head=NULL;
struct co
{
int x;
int clear;
}count[10]={0,-1,0,-1,0,-1,0,-1,0,-1,0,-1,0,-1,0,-1,0,-1,0,-1};
InitGra()
{
int dr=DETECT,mode=0;
initgraph(&dr,&mode,"");
cleardevice();
}
void clearflash(struct star* s,int clear)
{
struct xing *c,*next;
int i;
c=s->son;
if(clear==0)
{
for(i=0;i<=119;i++)
putpixel(c[i].x,c[i].y,BLACK);
}
else if(clear==1)
{
for(i=120;i<=239;i++)
putpixel(c[i].x,c[i].y,BLACK);
}
else if(clear==2)
{
for(i=240;i<=359;i++)
putpixel(c[i].x,c[i].y,BLACK);
}
else if(clear==3)
{
for(i=360;i<=479;i++)
putpixel(c[i].x,c[i].y,BLACK);
}
else if(clear==4)
{
for(i=480;i<=599;i++)
putpixel(c[i].x,c[i].y,BLACK);
free(c);
}
}
void clear()
{
free(head);
}
void recreat(struct star *p)
{
p->x=random(450)+50;
p->y=480;
p->color=random(15)+1;
p->end=random(140)+50;
p->son=NULL;
}
void flash(struct star* f,int d)
{struct xing* c;
int i;
c=f->son;
if(count[d].clear==-1)
{
for(i=0;i<NUM_OF_XING;i++)
{
putpixel(c[i].x,c[i].y,BLACK);
c[i].x+=random(101)-50;
c[i].y+=random(101)-50;
c[i].color=random(15)+1;
putpixel(c[i].x,c[i].y,c[i].color);
}
count[d].x++;
}
if(count[d].x>15)
{
count[d].clear++;
clearflash(f,count[d].clear);
if(count[d].clear==4)
{
recreat(f);
count[d].x=0;
count[d].clear=-1;
}
}
}
int createmainstar()
{ struct star *creat;
int i;
creat=(struct star*)malloc(NUM*sizeof(struct star));
if (creat==NULL)
{printf("Memory is not enough!");
return(0);
}
head=creat;
for(i=0;i<NUM;i++)
{
creat[i].x=random(450)+50;
creat[i].y=480;
creat[i].end=random(140)+50;
creat[i].color=random(15)+1;
creat[i].son=NULL;
}
}
void creatxing(struct star* birth)
{
struct star *new;
struct xing *s;
int i,r,cr,a;
s=(struct xing*)malloc(NUM_OF_XING*sizeof(struct xing));
if(!s)
{
printf("Memory is not enough!");
}
birth->son=s;
for(i=0;i<NUM_OF_XING;i++)
{
s[i].x=birth->x;
s[i].y=birth->y;
s[i].color=random(15)+1;
}
}
void run()
{struct star *s;
int i;
s=head;
for(i=0;i<NUM;i++)
{
if(s[i].son!=NULL)
{
flash(&s[i],i);
}
else
{
setcolor(0);
setfillstyle(1,0);
fillellipse(s[i].x,s[i].y,1,1);
if(fabs(s[i].y-s[i].end)<5)
{
creatxing(&s[i]);
continue;
}
s[i].y-=1;
setcolor(s[i].color);
setfillstyle(1,s[i].color);
fillellipse(s[i].x,s[i].y,1,1);
delay(1000);
}
}
}
void main()
{
InitGra();
randomize();
createmainstar();
while(!kbhit())
{
run();
}
clear();
closegraph();
}
评论0