- /**
- *
- * @Name : lab3.c
- * @Func : 画一个杠杆,绕着一个转轴转动。
- * 它的转动同时带动着一个滑块的运动
- *
- *
- */
- #include <graphics.h>
- #include <conio.h>
- #include <stdlib.h>
- #include <math.h>
- #define pi 3.14
- void InitGraph()
- {
- int driver, gmode;
- driver = DETECT;
- registerbgidriver(EGAVGA_driver);
- initgraph(&driver, &gmode, " ");
- }
- int main()
- {
- int theta;
- float i;
- float tmp1, tmp2, tmp3;
- InitGraph();
- while (!kbhit())
- {
- for (theta = 0; theta < 360; theta++)
- {
- i = theta*pi/180;
- tmp1 = 150+50*cos(i);
- tmp2 = sqrt(150*150-50*sin(i)*50*sin(i));
- tmp3 = tmp1+tmp2;
- line(150, 240, 150+50*cos(i), 240+50*sin(i));
- line(150+50*cos(i), 240+50*sin(i), tmp3,240);
- rectangle(tmp3-10, 230, tmp3+10, 250);
- delay(500);
- cleardevice();
- }
- }
- getch();
- closegraph();
- return 0;
- }
- //该片段来自于http://www.codesnippet.cn/detail/020720149901.html
来源: http://www.codesnippet.cn/detail/020720149901.html