应用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 c=RED;
int x=320,y=225;
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 */
wg=malloc(p_w_picpathsize(200,7,206,16));
rg=malloc(p_w_picpathsize(240,7,246,16));
vg=malloc(p_w_picpathsize(280,7,286,16));
fy=malloc(p_w_picpathsize(200,7,206,16));
getp_w_picpath(200,7,206,16,wg);
getp_w_picpath(240,7,246,16,rg);
getp_w_picpath(280,7,286,16,vg);
cleardevice();
/* write the box */
setcolor(YELLOW);
rectangle(4,19,637,447);
x1=x-3;
y1=y+1;
x2=x+3;
y2=y+10;
getp_w_picpath(x1,y1,x2,y2,fy);
putp_w_picpath(x1,y1,vg,XOR_PUT);
/* receive the command */
for (;;)
while (bioskey(1)==0);
k=bioskey(0);
putp_w_picpath(x1,y1,fy,AND_PUT);
if (((k&0x00ff)|0x00)==0)
k1=k&0xff?0:k>>8; /* k1 is the specialkey value */
else
k2=k&0x00ff; /* k2 is the non-specialkey value */
if (((k&0x00ff)|0x00)==0) /* Special key */
switch(k1)
case 45:
restorecrtmode();
exit(0);
case 72:
if (y>20)
y=y-1;
break;
case 75:
if (x>5)
x=x-1;
break;
case 77:
if (x<636)
x=x+1;
break;
case 80:
if (y<446)
y=y+1;
break;
case 71:
if ((x>5)&&(y>20))
x=x-1;
y=y-1;
break;
case 79:
if ((x>5)&&(y<446))
x=x-1;
y=y+1;
break;
case 73:
if ((x<636)&&(y>20))
x=x+1;
y=y-1;
break;
case 81:
if ((x<636)&&(y<446))
x=x+1;
y=y+1;
break; x1=x-3;
y1=y+1;
x2=x+3;
y2=y+10;
getp_w_picpath(x1,y1,x2,y2,fy);
/* non-special key */[Page]
switch(k2)
case 118: /* \'v\' */
case 86: /* \'V\' */
putp_w_picpath(x1,y1,vg,OR_PUT);
break;
case 119: /* \'w\' */
case 87: /* \'W\' */
putp_w_picpath(x1,y1,wg,OR_PUT);
putpixel(x,y,c);
break;
case 114: /* \'r\' */
case 82: /* \'R\' */
putp_w_picpath(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;
fp=fopen(fname,\"wb\");
for(i=0;i<4;i++)
outportb(0x3CE,4);
outportb(0x3CF,i);
ptr=(char far *) 0xA0000000L;
for (j=0;j<38400L;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 k4=1;
register long j;
char far *ptr;
fp=fopen(fname,\"rb\");
for (i=0;i<4;i++)
outportb(0x3C4,2);
outportb(0x3C5,k4);
ptr=(char far *)0xA0000000L;
for (j=0;j<38400L;j++)
*ptr=getc(fp);
ptr++;
k4*=2;
fclose(fp);
outportb(0x3C5,0xF); 三、結束語 該程序在Turbo C 2.0環境下運行通過,使用效果良好。可以根據具體需要,對該程序進行擴充,以增加繪圖功能。 職場 休閑 c
# include \"stdio.h\"
# include \"fcntl.h\"
# include \"stdlib.h\"
main()
void save(),load();
void *wg,*rg,*vg,*fy;
int driver,mode;
int c=RED;
int x=320,y=225;
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 */
wg=malloc(p_w_picpathsize(200,7,206,16));
rg=malloc(p_w_picpathsize(240,7,246,16));
vg=malloc(p_w_picpathsize(280,7,286,16));
fy=malloc(p_w_picpathsize(200,7,206,16));
getp_w_picpath(200,7,206,16,wg);
getp_w_picpath(240,7,246,16,rg);
getp_w_picpath(280,7,286,16,vg);
cleardevice();
/* write the box */
setcolor(YELLOW);
rectangle(4,19,637,447);
x1=x-3;
y1=y+1;
x2=x+3;
y2=y+10;
getp_w_picpath(x1,y1,x2,y2,fy);
putp_w_picpath(x1,y1,vg,XOR_PUT);
/* receive the command */
for (;;)
while (bioskey(1)==0);
k=bioskey(0);
putp_w_picpath(x1,y1,fy,AND_PUT);
if (((k&0x00ff)|0x00)==0)
k1=k&0xff?0:k>>8; /* k1 is the specialkey value */
else
k2=k&0x00ff; /* k2 is the non-specialkey value */
if (((k&0x00ff)|0x00)==0) /* Special key */
switch(k1)
case 45:
restorecrtmode();
exit(0);
case 72:
if (y>20)
y=y-1;
break;
case 75:
if (x>5)
x=x-1;
break;
case 77:
if (x<636)
x=x+1;
break;
case 80:
if (y<446)
y=y+1;
break;
case 71:
if ((x>5)&&(y>20))
x=x-1;
y=y-1;
break;
case 79:
if ((x>5)&&(y<446))
x=x-1;
y=y+1;
break;
case 73:
if ((x<636)&&(y>20))
x=x+1;
y=y-1;
break;
case 81:
if ((x<636)&&(y<446))
x=x+1;
y=y+1;
break; x1=x-3;
y1=y+1;
x2=x+3;
y2=y+10;
getp_w_picpath(x1,y1,x2,y2,fy);
/* non-special key */[Page]
switch(k2)
case 118: /* \'v\' */
case 86: /* \'V\' */
putp_w_picpath(x1,y1,vg,OR_PUT);
break;
case 119: /* \'w\' */
case 87: /* \'W\' */
putp_w_picpath(x1,y1,wg,OR_PUT);
putpixel(x,y,c);
break;
case 114: /* \'r\' */
case 82: /* \'R\' */
putp_w_picpath(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;
fp=fopen(fname,\"wb\");
for(i=0;i<4;i++)
outportb(0x3CE,4);
outportb(0x3CF,i);
ptr=(char far *) 0xA0000000L;
for (j=0;j<38400L;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 k4=1;
register long j;
char far *ptr;
fp=fopen(fname,\"rb\");
for (i=0;i<4;i++)
outportb(0x3C4,2);
outportb(0x3C5,k4);
ptr=(char far *)0xA0000000L;
for (j=0;j<38400L;j++)
*ptr=getc(fp);
ptr++;
k4*=2;
fclose(fp);
outportb(0x3C5,0xF); 三、結束語 該程序在Turbo C 2.0環境下運行通過,使用效果良好。可以根據具體需要,對該程序進行擴充,以增加繪圖功能。 職場 休閑 c
0
微博 QQ 微信收藏
上一篇:Vmware Infrastru... 下一篇:每個程序員都要學C語言的五個理由 siwei198743篇文章,6W+人氣,0粉絲
Ctrl+Enter?發布
發布
取消
推薦專欄更多
微服務技術架構和大數據治理實戰大數據時代的微服務之路
共18章?|?純潔微笑
¥51.00 669人訂閱
訂???閱 基于Python的DevOps實戰自動化運維開發新概念
共20章?|?撫琴煮酒
¥51.00 428人訂閱
訂???閱猜你喜歡
我的友情鏈接 怎么去掉這個錯誤 Java線程:線程的調度-休眠 我們不得不面對的中年職場危機 職場終極密籍--記我的職業生涯 用光影魔術手制作一寸照片(8張一寸) 我的IT職場生涯: 畢業4年,月薪過萬 Linux關閉休眠和屏保模式 年薪從0到10萬-我的IT職場經驗總結 Windows7刪除休眠文件hiberfil.sys節省大量C盤空間 致IT同仁 — IT人士常犯的17個職場錯誤 “跳槽加薪”現象,無奈的職場規則 C++應用程序性能優化(三)——C++語言特性性能分析 GNU開發工具——CMake構建Qt工程實踐 GNU開發工具——CMake進階 Linux g++ 鏈接庫 編譯、鏈接 以及 Makefile編寫 Linux 環境下 gcc 鏈接庫 編譯、鏈接(概覽) 以及 自動化工具Makefile的編寫 某網絡監視器完整逆向 萬人直播網絡架構與CDN網絡 Python C API 使用詳解(二)掃一掃,領取大禮包
0
分享 siwei1987轉載于:https://blog.51cto.com/siwei1987/120391
新人創作打卡挑戰賽發博客就能抽獎!定制產品紅包拿不停!總結
以上是生活随笔為你收集整理的应用C语言编辑画图程序的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 做技术支持的工作心得
- 下一篇: 中信国健临床通讯2011年1月第1期目录