📄 雨滴.c
字号:
#include "stdio.h"
#include "graphics.h"
#define LEN sizeof(struct rainDrop)
struct rainDrop
{
int startX;
int startY;
int endY;
int curX;
int curY;
int color;
int step;
int length;
};
struct rainDrop *creatDrop(void)
{
struct rainDrop *p;
p=(struct rainDrop *)malloc(LEN);
p->startX=rand()%640;
p->startY=rand()%430;
p->endY=430+rand()%50;
p->curX=p->startX;
p->curY=p->startY;
p->step=8;
p->color=rand()%15+1;
p->length=rand()%10+10;
return(p);
}
void recreatDrop(struct rainDrop *p)
{
p->startX=rand()%640;
p->startY=rand()%430;
p->endY=430+rand()%50;
p->curX=p->startX;
p->curY=p->startY;
p->step=8;
p->color=rand()%15+1;
p->length=rand()%10+10;
}
void initgraphics()
{
int gmode,gdriver;
gdriver=DETECT;
initgraph(&gdriver,&gmode,"");
}
void drawLine(struct rainDrop *p){
setcolor(p->color);
line(p->startX,p->startY,p->curX,p->curY);
}
void clearLine(struct rainDrop *p){
setcolor(BLACK);
line(p->startX,p->startY,p->curX,p->curY);
}
void updateLine(struct rainDrop *p){
if(p->step%5==0)
p->step++;
p->curY+=p->step;
p->startY=p->curY-p->length;
}
void clearAll()
{
closegraph();
}
void rainDropDown(struct rainDrop *p){
clearLine(p);
updateLine(p);
drawLine(p);
}
main()
{
int i;
struct rainDrop *p1=creatDrop();
initgraphics();
while(!kbhit()){
rainDropDown(p1);
delay(5000);
if(p1->curY>p1->endY){
clearLine(p1);
recreatDrop(p1);
}
}
getch();
clearAll();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -