雨滴.c

来自「C语言实现雨滴模拟」· C语言 代码 · 共 62 行

C
62
字号
#include "stdio.h"
#include "graphics.h"

void initgraphics()
{
    int gmode,gdriver;
    gdriver=DETECT;
    initgraph(&gdriver,&gmode,"");
}
void drawLine(int x,int y,int nx,int ny,int color){
	       setcolor(color);
		line(x,y,nx,ny);
	}
void clearLine(int x,int y,int nx,int ny){
	       setcolor(BLACK);
		line(x,y,nx,ny);
	}
void updateLine(int x,int y,int nx,int ny,int color,int step){
	        setcolor(color);
		 line(x,y+step,nx,ny+step);
	}
void clearAll()
{       
    closegraph();
}
void rainDropDown(int x,int y,int nx,int ny,int color,int step){
	            drawLine(x,y,nx,ny,color);
		     clearLine(x,y,nx,ny);
		     updateLine(x,y,nx,ny,color,step); 
			     
	}
main()
{
    int i;    
    initgraphics(); 
       while(!kbhit()){              
		    for(i=0;i<300;i++){    
			     
			    drawLine(130,i,130,50+i,RED);
                        
			    clearLine(130,i,130,50+i);
                       
			    updateLine(130,i,130,50+i,RED,1);  
			    delay(5000);
                     
                        rainDropDown(170,i,170,50+i,GREEN,1);
                        delay(5000);
			      
		    }  
		    setcolor(BLACK);
			clearLine(130,i,130,50+i);	     
			clearLine(170,i,170,50+i);
		}    
		     
	         
	        
		    
     
    getch();
    clearAll();

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?