我正在尝试设计一个风扇并使用 C 语言使线条旋转。
这是我的代码:
#include<stdio.h>
#include<graphics.h>
#include<math.h>
void main(){
int gd=DETECT,gm=0,xr,yr,xr1,yr1,xr2,yr2,x,y,x1,y1,x2,y2;
int x3,y3,i;
float rad;
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
x=getmaxx()/2;
y=getmaxy()/2;
printf("x1 and y1:");
scanf("%d %d",&x1,&y1);
printf("x2 and y2:");
scanf("%d %d",&x2,&y2);
printf("x3 and y3:");
scanf("%d %d",&x3,&y3);
printf("\n\n");
setcolor(RED);
line(x,y,x1,y1);
line(x,y,x2,y1);
line(x,y,x3,y3);
rad=toRadians(1);
for(i=0;i<60;i++){
xr=x+((x1-x)*cos(0.017)-(y1-y)*sin(0.017));
yr=y+((x1-x)*sin(0.017)+(y1-y)*cos(0.017));
xr1=x+((x2-x)*cos(0.017)-(y2-y)*sin(0.017));
yr1=y+((x2-x)*sin(0.017)+(y2-y)*cos(0.017));
xr2=x+((x3-x)*cos(0.017)-(y3-y)*sin(0.017));
yr2=y+((x3-x)*sin(0.017)+(y3-y)*cos(0.017));
setcolor(RED);
line(x,y,xr,yr);
line(x,y,xr1,yr1);
line(x,y,xr2,yr2);
x1=xr;
y1=yr;
x2=xr1;
y2=yr1;
x3=xr2;
y3=yr2;
delay(500);
cleardevice();
}
getch();
closegraph();
}
问题是线条不会以同步的方式旋转。就像一条线在旋转,然后在一段时间后第二条线开始旋转,依此类推。谁能帮帮我吗?