微波炉热饭用什么碗:如何在这个时钟程序中镶上刻度

来源:百度文库 编辑:高考问答 时间:2024/05/02 06:52:31
#include<graphics.h>
#include<math.h>
#include<dos.h>
#define PI 3.1415926
#define x0 320
#define y0 240
void DrawClock(int x,int y,int color)
{ int r=100;
float th;
setcolor(color);
circle(x,y,r);
circle(x,y,2);
}
void DrawHand(int x,int y,float th,int l,int color)
{
int x1,y1;
x1=x+l*sin(th);
y1=y-l*cos(th);
setcolor(color);
line(x,y,x1,y1);
}

void main()
{int gdriver=DETECT,gmode;
struct time curtime;
float th_hour,th_min,th_sec;
initgraph(&gdriver,&gmode,"");
setbkcolor(0);
while(! kbhit())
{
DrawClock(x0,y0,14);
gettime(&curtime);
gotoxy(35,20);

th_sec=(float)curtime.ti_sec*0.1047197551; /*2π/60=0.1047197551*/
th_min=(float)curtime.ti_min*0.1047197551+th_sec/60.0;
th_hour=(float)curtime.ti_hour*0.523598775+th_min/12.0; /* 2π/12=0.5235987755 */
DrawHand(x0,y0,th_hour,50,2);
DrawHand(x0,y0,th_min,70,3);
DrawHand(x0,y0,th_sec,90,12);
sleep(1);
cleardevice();
}
closegraph();
}