www.pudn.com > tuxingxue.rar > Azhonghe.c


#include  
#include  
#include  
#include  
 
 
void Initialize() 
{ 
   int graphdriver,graphmode,errorcode; 
       graphdriver=DETECT; 
       initgraph(&graphdriver,&graphmode,"\tc\bgi"); 
       errorcode=graphresult(); 
       if(errorcode!=grOk) 
       { 
	 printf("graphics system error:%s",grapherrormsg(errorcode)); 
	 exit(1); 
       } 
} 
 
 
Midpointline(x0,y0,x1,y1,YELLOW) 
int x0,y0,x1,y1,YELLOW; 
{int a,b,delta1,delta2,d,x,y; 
a=y0-y1; 
b=x1-x0; 
d=2*a+b; 
delta1=2*a; 
delta2=2*(a+b); 
x=x0; 
y=y0; 
putpixel(x,y,YELLOW); 
while(x0) 
{ 
if(d2<0) 
{ 
d2+=b*b*(2*x+2)+a*a*(-2*y+3); 
x++; 
y--; 
} 
else 
{ 
d2+=a*a*(-2*y+3); 
y--; 
} 
putpixel(m+x,n+y,color); 
putpixel(m+x,n-y,color); 
putpixel(m-x,n+y,color); 
putpixel(m-x,n-y,color); 
} 
} 
 
 
main() 
{ int color=1; 
  int x0,y0,x1,y1; 
  int r; 
  int a,b; 
  unsigned int Choice; 
  Initialize(); 
  gotoxy(20,1); 
  printf("the unit of graphics:\n"); 
  printf("************************99123009's graphic work********************************\n"); 
  printf("  0.Quit\n"); 
  printf("  1.Line(Midpointline)\n"); 
  printf("  2.Circle(MidpointCircle)\n"); 
  printf("  3.Ellipse(MidpointEllipse)\n"); 
  printf("input the Choice: "); 
  scanf("%d",&Choice); 
  switch(Choice) 
  { 
  case 0:    exit(0); 
	     break; 
  case 1: 
	     printf("the numbers :"); 
	     scanf("%d%d%d%d",&x0,&y0,&x1,&y1); 
	     printf("the color : "); 
	     scanf("%d",&color); 
	     Midpointline(x0,y0,x1,y1,color); 
	      setbkcolor(color+3); 
	     break; 
 
  case 2:    printf("the radius : "); 
	     scanf("%d",&r); 
	     printf("the color : "); 
	     scanf("%d",&color); 
	     MidpointCircle(r,color); 
	     break; 
 
  case 3:    printf("enter the a and b: "); 
	     scanf("%d%d",&a,&b); 
	     printf("enter the color:"); 
	     scanf("%d",&color); 
	     MidpointEllipse(a,b,color); 
	     break; 
 
 
   } 
   getch(); 
   closegraph(); 
 
 
}