C 實戰練習題目60

題目:畫圖,綜合例子2。(在TC中實現)。html

程序分析:無。學習

程序源代碼:spa

 1 #include "graphics.h"
 2 #define LEFT 0
 3 #define TOP 0
 4 #define RIGHT 639
 5 #define BOTTOM 479
 6 #define LINES 400
 7 #define MAXCOLOR 15
 8 int main()
 9 {
10     int driver,mode,error;
11     int x1,y1;
12     int x2,y2;
13     int dx1,dy1,dx2,dy2,i=1;
14     int count=0;
15     int color=0;
16     driver=VGA;
17     mode=VGAHI;
18     initgraph(&driver,&mode,"");
19     x1=x2=y1=y2=10;
20     dx1=dy1=2;
21     dx2=dy2=3;
22     while(!kbhit())
23     {
24         line(x1,y1,x2,y2);
25         x1+=dx1;y1+=dy1;
26         x2+=dx2;y2+dy2;
27         if(x1<=LEFT||x1>=RIGHT)
28             dx1=-dx1;
29         if(y1<=TOP||y1>=BOTTOM)
30             dy1=-dy1;
31         if(x2<=LEFT||x2>=RIGHT)
32             dx2=-dx2;
33         if(y2<=TOP||y2>=BOTTOM)
34                 dy2=-dy2;
35         if(++count>LINES)
36         {
37             setcolor(color);
38             color=(color>=MAXCOLOR)?0:++color;
39         }
40     }
41     closegraph();
42 }

感謝你的閱讀,請用心感悟!但願能夠幫到愛學習的你!!分享也是一種快樂!!!請接力。。。code

點擊查看原文,謝謝!htm

相關文章
相關標籤/搜索