下为小可编的一小程序,是绘制基本图形的,内有些许漏洞,请各位大侠帮帮忙,指点一二!
拜谢!
#include<DOS.H>
#include<graphics.h>
#include<stdlib.h>
#include<bios.h>
main()
{
union REGS i,o;
int driver=DETECT,mode=0;
int x,y,c1,c2,color=0;
int x1=0,y1=0,x2=0,y2=0;
int choice;
int flag=0;
float R;
log:printf("choice:1-Line 2-Rectangle 3-Circle\n");
printf("Please input the choice:");
scanf("%d",&choice);
initgraph(&driver,&mode,"C:\\TC\\BGI");
setbkcolor(color);
setcolor(2);
i.x.ax=32;/*鼠标驱动*/
int86(0X33,&i,&o);
i.x.ax=0; /*初始化鼠标*/
int86(0X33,&i,&o);
i.x.ax=1; /*显示鼠标*/
int86(0x33,&i,&o);
while(!bioskey(1)) /*kbhit()检测按键*/
{
i.x.ax=6;/*检测左键释放信息*/
i.x.bx=0;
int86(0x33,&i,&o);
x=o.x.cx;
y=o.x.dx;
c1=o.x.ax;
i.x.ax=5;/*检测右键按下信息*/
i.x.bx=1;
int86(0x33,&i,&o);
c2=o.x.ax;
if(c2==2) /*按下右键*/
{
closegraph();
printf("%d",&flag);
goto log;
}
if(c1==1) /*释放左键*/
{
i.x.ax=2;
int86(0x33,&i,&o);
i.x.ax=1;
int86(0x33,&i,&o);
if(!flag)
{
x1=x;
y1=y;
flag=1;
fillellipse(x1,y1,2,2);
}
else
{
x2=x;
y2=y;
fillellipse(x2,y2,2,2);
switch(choice)
{
case 1:
line(x1,y1,x2,y2);
break;
case 2:
rectangle(x1,y1,x2,y2);
break;
case 3:
R=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))/2;
circle((x1+x2)/2,(y1+y2)/2,R);
break;
default:
closegraph();
}
flag=0;
}
}
}
}