- 相關(guān)推薦
如何實(shí)現(xiàn)C語言畫圖教程
C語言有豐富的數(shù)據(jù)結(jié)構(gòu)和運(yùn)算符。包含了各種數(shù)據(jù)結(jié)構(gòu),如整型、數(shù)組類型、指針類型和聯(lián)合類型等,用來實(shí)現(xiàn)各種數(shù)據(jù)結(jié)構(gòu)的運(yùn)算。以下是小編為大家搜索整理的C語言如何實(shí)現(xiàn)畫圖教程,希望能給大家?guī)韼椭?更多精彩內(nèi)容請(qǐng)及時(shí)關(guān)注我們考試網(wǎng)!
程序中定義了幾個(gè)特殊鍵:
"V”:畫筆提起
"W”:開始畫圖
"R”:開始擦圖
"S”:當(dāng)前圖形存入文件
"E”:調(diào)出已有文件
"C”:畫圓
程序一運(yùn)行,屏幕上出現(xiàn)一個(gè)黃色的邊框來設(shè)定畫圖的區(qū)域,區(qū)域中間出現(xiàn)提起的畫筆符號(hào) ,當(dāng)按下”W“鍵時(shí),畫筆符號(hào)變?yōu)?,此時(shí)可移動(dòng)方向鍵(上、下、左、右、左上、左下、右上、右下)來畫圖;當(dāng)按下”R“鍵時(shí),畫筆符號(hào)變?yōu)?,此時(shí)可移動(dòng)方向鍵來擦圖;在畫圖過程中,按下“C”鍵,可畫出一個(gè)半徑為20個(gè)象素點(diǎn)的圓;當(dāng)結(jié)束畫圖時(shí),按下“S”鍵,將畫好的圖形存盤;按下“E”鍵可調(diào)出已有的圖形進(jìn)行編輯。
3.源程序清單
# 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: c");
/* 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(imagesize(200,7,206,16));
rg=malloc(imagesize(240,7,246,16));
vg=malloc(imagesize(280,7,286,16));
fy=malloc(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);
x1=x-3;
y1=y+1;
x2=x+3;
y2=y+10;
getimage(x1,y1,x2,y2,fy);
putimage(x1,y1,vg,XOR_PUT);
/* receive the command */
for (;;)
while (bioskey(1)==0);
k=bioskey(0);
putimage(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;
【如何實(shí)現(xiàn)C語言畫圖教程】相關(guān)文章:
C語言程序的實(shí)現(xiàn)09-27
C語言函數(shù)遞歸教程03-30
C語言的HashTable簡單實(shí)現(xiàn)04-01
如何理解C語言指針03-27
如何搭建C語言環(huán)境12-03
如何學(xué)習(xí)c語言最好?03-31
C語言如何輸出菱形11-08