哥哥,帮我改一下这个程序嘛,这样实现画图的时候,可以选择颜色,谢谢了,求你了,赶时间啦,谢谢啦
:confused: #include
#include
#include
#include
#include
#include
#include
#include
#define COLOR WHITE
#define F1 59
#define F2 60
#define UP 72
#define DOWN 80
#define LEFT 75
#define RIGHT 77
#define HOME 71
#define END 79
#define PAGEUP 73
#define PAGEDOWN 81
void Menu(void);
void Save(void);
void Load(void);
void Xhairs(int a,int b);
union k
{
char c[2];
int i;
};
typedef union k KEY;
KEY key;
struct dot
{
int x;
int y;
};
typedef struct dot DOT;
DOT dis;
main()
{
int inc=1,k,j,m,r;
int driver,mode;
int again=1;
DOT firstdot,secdot;
dis.x=200;
dis.y=200;
driver=DETECT;
mode=VGAHI;
initgraph(&driver,&mode,"c:\\bc\\bgi");
setbkcolor(BLUE);
cleardevice();
setcolor(YELLOW);
Xhairs(dis.x,dis.y);
while(key.c[0]!='q')
{
Menu();
key.i=bioskey(0);
if(!key.c[0])
{
Xhairs(dis.x,dis.y);
switch(key.c[1])
{
case LEFT: dis.x-=inc;
break;
case RIGHT: dis.x+=inc;
break;
case UP: dis.y-=inc;
break;
case DOWN: dis.y+=inc;
break;
case HOME: dis.x-=inc;
dis.y-=inc;
break;
case PAGEUP:dis.x+=inc;
dis.y-=inc;
break;
case END: dis.x-=inc;
dis.y+=inc;
break;
case PAGEDOWN:dis.x+=inc;
dis.y+=inc;
break;
case F1: inc=1;
break;
case F2: inc=5;
break;
}
Xhairs(dis.x,dis.y);
}
else
{
switch(tolower(key.c[0]))
{
case 'a': putpixel(dis.x,dis.y,COLOR);
firstdot.x=dis.x;
firstdot.y=dis.y;
break;
case 'b': putpixel(dis.x,dis.y,COLOR);
secdot.x=dis.x;
secdot.y=dis.y;
break;
case 'l': line(firstdot.x,firstdot.y,secdot.x,secdot.y);
break;
case 'o': r=sqrt(fabs((secdot.x-firstdot.x)*(secdot.x-firstdot.x)+(secdot.y-firstdot.y)*(secdot.y-firstdot.y)));
circle(firstdot.x,firstdot.y,r); break;
case 'h': rectangle(firstdot.x,firstdot.y,secdot.x,secdot.y);
break;
case 'c': cleardevice();Xhairs(dis.x,dis.y);
break;
case 'w': Save();
break;
case 'r': Load();
break;
}
}
}
closegraph();
}
void Xhairs(int a,int b)
{
int i;
for(i=a-5;i<=a+5;i++)
putpixel(i,b,15^getpixel(i,b));
for(i=b-5;i<=b+5;i++)
putpixel(a,i,15^getpixel(a,i));
}
void Menu(void)
{
#define STARTX 10
#define STARTY 22
#define DISTANCE 30
int i;
char *menu_name[]={"a:start point.","b:end point.","l:draw line.","o:draw circle.","h:draw box.","c:clear screen.","F1:step=1.","F2:step=5","Home Pageup","End PageDown.","w:save graph","r:load graph","q:quit"};
setcolor(WHITE);
rectangle(5,5,150,470);
rectangle(155,5,635,470);
setcolor(LIGHTBLUE);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,2);
outtextxy(36,STARTY,"menu");
setcolor(YELLOW);
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
for(i=0;i<=14;i++)
outtextxy(STARTX,STARTY+(i+1)*DISTANCE,menu_name);
}
void Save(void)
{
int i,j;
FILE *fp;
if((fp=fopen("graph.dat","w+"))==NULL)
{
printf("cannot open this file!");
exit(0);
}
for(i=5;i<=470;i++)
{
for(j=155;j<=635;j++)
{
fputc(getpixel(j,i),fp);
}
}
fclose(fp);
outtextxy(260,471,"save over!");
}
void Load(void)
{
int i,j;
FILE *fp;
if((fp=fopen("graph.dat","r+"))==NULL)
{
printf("cannot open this file!");
exit(0);
}
outtextxy(280,471,"loading......");
for(i=5;i<470;i++)
{
for(j=155;j<=635;j++)
putpixel(j,i,fgetc(fp));
}
fclose(fp);
outtextxy(368,471,"over");
}
--------------------next---------------------
哥哥,帮我改一下这个程序嘛,这样实现画图的时候,可以选择颜色,谢谢了,求你了,赶时间啦,谢谢啦
:confused: #include
#include
#include
#include
#include
#include
#include
#include
#define COLOR WHITE
#define F1 59
#define F2 60
#define UP 72
#define DOWN 80
#define LEFT 75
#define RIGHT 77
#define HOME 71
#define END 79
#define PAGEUP 73
#define PAGEDOWN 81
void Menu(void);
void Save(void);
void Load(void);
void Xhairs(int a,int b);
union k
{
char c[2];
int i;
};
typedef union k KEY;
KEY key;
struct dot
{
int x;
int y;
};
typedef struct dot DOT;
DOT dis;
main()
{
int inc=1,k,j,m,r;
int driver,mode;
int again=1;
DOT firstdot,secdot;
dis.x=200;
dis.y=200;
driver=DETECT;
mode=VGAHI;
initgraph(&driver,&mode,"c:\\bc\\bgi");
setbkcolor(BLUE);
cleardevice();
setcolor(YELLOW);
Xhairs(dis.x,dis.y);
while(key.c[0]!='q')
{
Menu();
key.i=bioskey(0);
if(!key.c[0])
{
Xhairs(dis.x,dis.y);
switch(key.c[1])
{
case LEFT: dis.x-=inc;
break;
case RIGHT: dis.x+=inc;
break;
case UP: dis.y-=inc;
break;
case DOWN: dis.y+=inc;
break;
case HOME: dis.x-=inc;
dis.y-=inc;
break;
case PAGEUP:dis.x+=inc;
dis.y-=inc;
break;
case END: dis.x-=inc;
dis.y+=inc;
break;
case PAGEDOWN:dis.x+=inc;
dis.y+=inc;
break;
case F1: inc=1;
break;
case F2: inc=5;
break;
}
Xhairs(dis.x,dis.y);
}
else
{
switch(tolower(key.c[0]))
{
case 'a': putpixel(dis.x,dis.y,COLOR);
firstdot.x=dis.x;
firstdot.y=dis.y;
break;
case 'b': putpixel(dis.x,dis.y,COLOR);
secdot.x=dis.x;
secdot.y=dis.y;
break;
case 'l': line(firstdot.x,firstdot.y,secdot.x,secdot.y);
break;
case 'o': r=sqrt(fabs((secdot.x-firstdot.x)*(secdot.x-firstdot.x)+(secdot.y-firstdot.y)*(secdot.y-firstdot.y)));
circle(firstdot.x,firstdot.y,r); break;
case 'h': rectangle(firstdot.x,firstdot.y,secdot.x,secdot.y);
break;
case 'c': cleardevice();Xhairs(dis.x,dis.y);
break;
case 'w': Save();
break;
case 'r': Load();
break;
}
}
}
closegraph();
}
void Xhairs(int a,int b)
{
int i;
for(i=a-5;i<=a+5;i++)
putpixel(i,b,15^getpixel(i,b));
for(i=b-5;i<=b+5;i++)
putpixel(a,i,15^getpixel(a,i));
}
void Menu(void)
{
#define STARTX 10
#define STARTY 22
#define DISTANCE 30
int i;
char *menu_name[]={"a:start point.","b:end point.","l:draw line.","o:draw circle.","h:draw box.","c:clear screen.","F1:step=1.","F2:step=5","Home Pageup","End PageDown.","w:save graph","r:load graph","q:quit"};
setcolor(WHITE);
rectangle(5,5,150,470);
rectangle(155,5,635,470);
setcolor(LIGHTBLUE);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,2);
outtextxy(36,STARTY,"menu");
setcolor(YELLOW);
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
for(i=0;i<=14;i++)
outtextxy(STARTX,STARTY+(i+1)*DISTANCE,menu_name);
}
void Save(void)
{
int i,j;
FILE *fp;
if((fp=fopen("graph.dat","w+"))==NULL)
{
printf("cannot open this file!");
exit(0);
}
for(i=5;i<=470;i++)
{
for(j=155;j<=635;j++)
{
fputc(getpixel(j,i),fp);
}
}
fclose(fp);
outtextxy(260,471,"save over!");
}
void Load(void)
{
int i,j;
FILE *fp;
if((fp=fopen("graph.dat","r+"))==NULL)
{
printf("cannot open this file!");
exit(0);
}
outtextxy(280,471,"loading......");
for(i=5;i<470;i++)
{
for(j=155;j<=635;j++)
putpixel(j,i,fgetc(fp));
}
fclose(fp);
outtextxy(368,471,"over");
}
--------------------next---------------------
阅读(316) | 评论(0) | 转发(0) |