来宾网站seo,荆州 商务 网站建设,上网建站推广,官网下载安装您可能感兴趣的话题#xff1a;C语言核心提示#xff1a;笔者在开发县级电网调度自动化系统的过程中,碰到一个要绘制电力系统一次接线图的问题笔者在开发县级电网调度自动化系统的过程中,碰到一个要绘制电力系统一次接线图的问题.由于电力系统一次接线图比较复杂,用一般的编程…您可能感兴趣的话题C语言核心提示笔者在开发县级电网调度自动化系统的过程中,碰到一个要绘制电力系统一次接线图的问题笔者在开发县级电网调度自动化系统的过程中,碰到一个要绘制电力系统一次接线图的问题.由于电力系统一次接线图比较复杂,用一般的编程方法来绘制比较困难,因此,笔者用C语言开发了一个手工绘制电力系统一次接线图的键盘绘图程序,使用该程序绘制的一次接线图符合用户需求,效果良好.一、使用方法程序中定义了几个特殊键:\V:画笔提起\W:开始画图\R:开始擦图\S:当前图形存入文件\E:调出已有文件\C:画圆程序一运行,屏幕上出现一个黄色的边框来设定画图的区域,区域中间出现提起的画笔符号 ,当按下W键时,画笔符号变为 ,此时可移动方向键(上、下、左、右、左上、左下、右上、右下)来画图;当按下R键时,画笔符号变为 ,此时可移动方向键来擦图;在画图过程中,按下C键,可画出一个半径为20个象素点的圆;当结束画图时,按下S键,将画好的图形存盘;按下E键可调出已有的图形进行编辑.二、源程序清单# include \graphics.h\# include \stdio.h\# include \fcntl.h\# include \stdlib.h\main()void save(),load();void *wg,*rg,*vg,*fy;int driver,mode;int cRED;int x320,y225;int x1,y1,x2,y2;int k,k1,k2;/* initialize grapher */detectgraph(driver,mode);initgraph(driver,mode,\c:\\tc\);/* write the pen */bar(200,10,206,16);line(203,7,200,10);line(203,7,206,10);line(243,7,240,16);line(243,7,246,16);line(283,7,280,10);line(283,7,286,10);line(283,7,283,16);/* save the pen */wgmalloc(imagesize(200,7,206,16));rgmalloc(imagesize(240,7,246,16));vgmalloc(imagesize(280,7,286,16));fymalloc(imagesize(200,7,206,16));getimage(200,7,206,16,wg);getimage(240,7,246,16,rg);getimage(280,7,286,16,vg);cleardevice();/* write the box */setcolor(YELLOW);rectangle(4,19,637,447);x1x-3;y1y1;x2x3;y2y10;getimage(x1,y1,x2,y2,fy);putimage(x1,y1,vg,XOR_PUT);/* receive the command */for (;;)while (bioskey(1)0);kbioskey(0);putimage(x1,y1,fy,AND_PUT);if (((k0x00ff)|0x00)0)k1k0xff?0:k8; /* k1 is the specialkey value */elsek2k0x00ff; /* k2 is the non-specialkey value */if (((k0x00ff)|0x00)0) /* Special key */switch(k1)case 45:restorecrtmode();exit(0);case 72:if (y20)yy-1;break;case 75:if (x5)xx-1;break;case 77:if (x636)xx1;break;case 80:if (y446)yy1;break;case 71:if ((x5)(y20))xx-1;yy-1;break;case 79:if ((x5)(y446))xx-1;yy1;break;case 73:if ((x636)(y20))xx1;yy-1;break;case 81:if ((x636)(y446))xx1;yy1;break;x1x-3;y1y1;x2x3;y2y10;getimage(x1,y1,x2,y2,fy);/* non-special key */[Page]switch(k2)case 118: /* \v\ */case 86: /* \V\ */putimage(x1,y1,vg,OR_PUT);break;case 119: /* \w\ */case 87: /* \W\ */putimage(x1,y1,wg,OR_PUT);putpixel(x,y,c);break;case 114: /* \r\ */case 82: /* \R\ */putimage(x1,y1,rg,OR_PUT);putpixel(x,y,BLACK);break;case 115: /* \s\ */case 83: /* \S\ */save(\pic.dat\);break;case 101: /* \e\ */case 69: /* \E\ */load(\pic.dat\);break;case 99: /*\c\*/case 67: /*\C\*/setcolor(RED);circle(x,y,20);break;default:continue;/* function for screen picture save*/void save(char *fname)FILE *fp;int i;register long j;char far *ptr;fpfopen(fname,\wb\);for(i0;i4;i)outportb(0x3CE,4);outportb(0x3CF,i);ptr(char far *) 0xA0000000L;for (j0;j38400L;j)putc(*ptr,fp);ptr;fclose(fp);outportb(0x3CF,0);/* function for screen picture display*/void load(char *fname)FILE *fp;register int i;int k41;register long j;char far *ptr;fpfopen(fname,\rb\);for (i0;i4;i)outportb(0x3C4,2);outportb(0x3C5,k4);ptr(char far *)0xA0000000L;for (j0;j38400L;j)*ptrgetc(fp);ptr;k4*2;fclose(fp);outportb(0x3C5,0xF);三、结束语该程序在Turbo C 2.0环境下运行通过,使用效果良好.可以根据具体需要,对该程序进行扩充,以增加绘图功能.