[求助]关于指针转动的实现
各位大虾们好,我想要知道怎样能够实现汽车表盘的模拟。关键是按“↑”键的时候表盘的指针会转动。松开指针会自己回到0刻度。想了好久也没什么头绪。如果是存图取图的话怎么才能实现指针的转动呢。还有就是按键时间的问题。新手求教。正在学习中呢。谢谢大家。谢谢。我自己写了一段代码,不知道问题出在哪里。希望各位能指点指点。谢谢。
#include<graphics.h>
#include<math.h>
#define PI 3.1415926
#define mid_x 320
#define mid_y 240
int main()
{
int i,l,j,x1,x2,y1,y2,x3,y3;
char ch;
int driver=DETECT,mode;
initgraph(&driver,&mode," ");
setbkcolor(BLACK);
while(!kbhit('q'))
{
setcolor(WHITE);
cleardevice();
setfillstyle(1,4);
pieslice(mid_x,mid_y,0,60,180);
setfillstyle(1,0);
pieslice(mid_x,mid_y,0,60,145);
setfillstyle(1,0);
pieslice(320,240,0,180,145);
arc(mid_x,mid_y,0,180,180);
circle(mid_x,mid_y,2);
line(500,240,140,240);
for(i=15;i<45;i++)
{
if(i%5==0)
l=20;
else
l=10;
x1=180*sin(i*6*PI/180)+320;
y1=180*cos(i*6*PI/180)+240;
x2=(180-l)*sin(i*6*PI/180)+320;
y2=(180-l)*cos(i*6*PI/180)+240;
line(x1,y1,x2,y2);
}
settextjustify(1,1);
outtextxy(320,80,"45");
outtextxy(160,230,"0");
outtextxy(480,230,"90");
outtextxy(400,100,"60");
outtextxy(240,100,"30");
outtextxy(450,160,"75");
outtextxy(180,160,"15");
x3=160*sin(j*6*PI/180)+320;
y3=160*cos(j*6*PI/180)+240;
j=45;
15<=j<=45;
ch=getch();
switch(ch)
{
case '\025':j=j+1;break;
case '\024':j=j-1;break;
}
setcolor(RED);
line(x3,y3,mid_x,mid_y);
getch();
}
return 0;
}