C语言的问题

#include <stdio.h>
#include <math.h>
#include <graphics.h>
#include <stdlib.h>
#include <time.h>
#include <dos.h>
#include <conio.h>

#define PI 3.1415926

#define RAINDROPLEN 15 /*  The length of a raindrop */
#define RAINTANGLE 0 /*  The tangle of each raindrop */
#define RAINDROPZ 0  /* The internal of each raindrop */
#define RAINCOLOR white /* The color of each raindrop */
#define RAINWAVELEVEL 40 /* The level of each wave */
#define DELAYTIME 2000 /* The internal of each flash of the screen */

/* Calculate the next X,Y of a raindrop */
#define RAINDROPNEXTX(n,m) (int)((RAINDROPLEN/m+n)*sin(RAINTANGLE*(PI/180)))
#define RAINDROPNEXTY(n,m) (int)((RAINDROPLEN/m+n)*cos(RAINTANGLE*(PI/180)))

#define RAINDROPS 100 /*  The total numbers of raindrops */

struct raindrop
{
int posx;
int posy;
int state; /* The current state of raindrop. 1 for raindrop. 2 for wave. */
int wavelevel; /* The current wave level */
};

void Init(struct raindrop *drops);
void DrawDrops(struct raindrop *drops); /* Draw all the raindrops */
void CalDrops(struct raindrop *drops); /* Calculate the next raindrops position */

int main(void)
{
struct raindrop drops[RAINDROPS];
int gdriver=DETECT,gmode,i=0;
initgraph(&gdriver,&gmode,""); /* Init graphic mode */
Init(drops);
setbkcolor(0);
while(!kbhit())
{
cleardevice();
DrawDrops(drops);
delay(DELAYTIME);
CalDrops(drops);
}
return 0;
}

void Init(struct raindrop *drops)
{
int i;
randomize();
for(i=0;i<RAINDROPS;i++,drops++)
{
drops->posx=random(600);
drops->posy=random(300);
drops->state=1;
drops->wavelevel=0;
}
}

void DrawDrops(struct raindrop *drops)
{
int i;
int endx,endy;
setcolor(WHITE);
for(i=0;i<RAINDROPS;i++,drops++)
{
if (drops->state==1)
{
endx=RAINDROPNEXTX(0,1);
endy=RAINDROPNEXTY(0,1);
line(drops->posx,drops->posy,drops->posx+endx,drops->posy+endy);
}
else
{

ellipse(drops->posx,drops->posy,0,360,1+(drops->wavelevel)*0.75,0.05+(drops->wavelevel)*0.15);
}
}
}

void CalDrops(struct raindrop *drops)
{
int i;
int endx,endy;
int temp;
for(i=0;i<RAINDROPS;i++,drops++)
{
if (drops->state==1)
{
endx=RAINDROPNEXTX(RAINDROPZ,10);
endy=RAINDROPNEXTY(RAINDROPZ,10);
if ((endx+drops->posx)>=640||(endy+drops->posy)>=400)
{
temp=random(100);
if (temp%2==0||(endx+drops->posx)>=680||(endy+drops->posy)>=550)
{
drops->state=2;
drops->wavelevel=1;
}
else
{
drops->posx=drops->posx+endx;
drops->posy=drops->posy+endy;
}

}
else
{
drops->posx=drops->posx+endx;
drops->posy=drops->posy+endy;
}
}
else
{
if ((drops->wavelevel)<RAINWAVELEVEL)
{

drops->wavelevel++;
}
else
{
drops->posx=random(600);
drops->posy=random(100);
drops->wavelevel=0;
drops->state=1;
}
}
}

• 本文已收录于以下专栏：

举报原因： 您举报文章：C语言的问题 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)