Analog Clock in C

/*WAP to illustrate an analog clock*/
#include<graphics.h>
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<dos.h>
#include<time.h>
#include<process.h>
#include<math.h>
void user();
float h,ma,hour,minute,sec,m,s;
void main()
{
int gdriver = DETECT, gmode, errorcode;
struct time t;
initgraph(&gdriver, &gmode, "C:/TC/BGI");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
loop:
gettime(&t);
hour=t.ti_hour;
minute=t.ti_min;
sec=t.ti_sec;
if(hour>11)
hour=hour-12;
h=90-(hour*30+minute/12);
ma=90-(minute*6);
s=90-(sec*6);
m=minute-minute/12;
cleardevice();
gotoxy(40,15);
printf("%2.0f:%2.0f:%2.0f",hour,minute,sec);
gotoxy(10,10);
setcolor(15);
circle(350,250,100);
setfillstyle(1,9);
circle(350,250,2);
circle(350,250,10);
outtextxy(335,200,"RADON");
setcolor(RED);
outtextxy(346,160,"12");
outtextxy(346,340,"6");
outtextxy(425,247,"3");
outtextxy(260,247,"9");
setcolor(7);
line(350,250,(350+70*cos(h*3.14/180)),(250-70*sin(h*3.14/180))); //hour hand
setcolor(10);
line(350,250,(350+90*cos(s*3.14/180)),(250-95*sin(s*3.14/180))); //second hand
setcolor(9);
line(350,250,(350+60*cos(ma*3.14/180)),(250-90*sin(ma*3.14/180))); //minute hand
setcolor(8);
if(sec>59)
{
sec=0;
m++;
m=6;
s=s-90;
if(m>59)
{
m=0;
h=6;
}
}
if(!kbhit()) //check for keystroke
{
sec++;
s=s-6;
delay(1000);
goto loop;
}
else //when key press
{
getch();
exit(0);
}
getch();
closegraph();
}

Post a Comment

0 Comments