繪製直線

/* 通過繪製4條直線,顯示一個矩形 */
#include <graphics.h>
main()
{
 int gdriver=DETECT,gmode;                 /* DETECT 由系統自動檢測顯示器的最高分辨率模式,並裝入相應的圖形驅動程序 */
 initgraph(&gdriver,&gmode,"c:\\TC201E\\bgi");   /* 初始化圖形系統 */
 cleardevice();                                   /* 清屏,並將當前點位置設置爲原點(0,0) */
 printf("\n Draw lines with function 'line'.");
 line(160,120,480,120);              /* line函數,在指定的兩點之間畫一條直線 */
 line(480,120,480,360);
 line(480,360,160,360);
 line(160,360,160,120);
 getch();
 
 cleardevice();
 getch();
 printf("\n Draw lines with function 'lineto'.");
 moveto(160,120);           /* moveto函數,將光標移動到指定的點 */
 lineto(480,120);              /* lineto函數, 從當前點位置到制定點位置畫一條直線 */
 lineto(480,360);
 lineto(160,360);
 lineto(160,120);
 getch();
 
 cleardevice();
 getch();
 printf("\n Draw lines with function 'linerel',");
 moveto(160,120);
 linerel(320,0);      /* linerel函數,使用相對座標畫直線:linerel(320,0) = lineto(160+320,120+0) */
 linerel(0,240);
 linerel(-320,0);
 linerel(0,240);
 getch();
 
 closegraph();
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章