C 實戰練習題目65

題目:一個最優美的圖案(在TC中實現)。html

程序分析:無。學習

程序源代碼:spa

 1 #include "graphics.h"
 2 #include "math.h"
 3 #include "dos.h"
 4 #include "conio.h"
 5 #include "stdlib.h"
 6 #include "stdio.h"
 7 #include "stdarg.h"
 8 #define MAXPTS 15
 9 #define PI 3.1415926
10 struct PTS { 11     int x,y; 12 }; 13 double AspectRatio=0.85; 14 void LineToDemo(void) 15 { 16     struct viewporttype vp; 17     struct PTS points[MAXPTS]; 18     int i, j, h, w, xcenter, ycenter; 19     int radius, angle, step; 20     double rads; 21     printf(" MoveTo / LineTo Demonstration" ); 22     getviewsettings( &vp ); 23     h = vp.bottom - vp.top; 24     w = vp.right - vp.left; 25     xcenter = w / 2; /* Determine the center of circle */
26     ycenter = h / 2; 27     radius = (h - 30) / (AspectRatio * 2); 28     step = 360 / MAXPTS; /* Determine # of increments */
29     angle = 0; /* Begin at zero degrees */
30     for( i=0 ; i<MAXPTS ; ++i ){ /* Determine circle intercepts */
31         rads = (double)angle * PI / 180.0; /* Convert angle to radians */
32         points[i].x = xcenter + (int)( cos(rads) * radius ); 33         points[i].y = ycenter - (int)( sin(rads) * radius * AspectRatio ); 34         angle += step; /* Move to next increment */
35  } 36     circle( xcenter, ycenter, radius ); /* Draw bounding circle */
37     for( i=0 ; i<MAXPTS ; ++i ){ /* Draw the cords to the circle */
38         for( j=i ; j<MAXPTS ; ++j ){ /* For each remaining intersect */
39             moveto(points[i].x, points[i].y); /* Move to beginning of cord */
40             lineto(points[j].x, points[j].y); /* Draw the cord */
41  } 42  } 43 } 44 int main() 45 { 46     int driver,mode; 47     driver=CGA;mode=CGAC0; 48     initgraph(&driver,&mode,""); 49     setcolor(3); 50  setbkcolor(GREEN); 51  LineToDemo(); 52 }

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

點擊查看原文,謝謝!htm

相關文章
相關標籤/搜索