在图形输出窗口中动态绘制四叶草。
1 #include <graphics.h> 2 #include <math.h> 3 #include <conio.h> 4 #define PI 3.1415926535 5 void main(void) 6 { 7 initgraph(640,480); 8 setcolor(GREEN); 9 setorigin(320,240); 10 double e; 11 int x1,y1,x2,y2; 12 for(double a=0;a<2*PI;a+=2*PI/720) 13 { 14 e=100*(1+sin(4*a)); 15 x1=(int)(e*cos(a)); 16 y1=(int)(e*sin(a)); 17 x2=(int)(e*cos(a+PI/5)); 18 y2=(int)(e*sin(a+PI/5)); 19 line(x1,y1,x2,y2); 20 Sleep(20); 21 } 22 getch(); 23 closegraph(); 24 }
时间: 2024-11-05 13:41:02