Analogue Clock - Anti _clockwise : Using C and graphics
Hey guys, here's the cool program to generate the analogue clock which rotates in anti clock wise direction. Today's world has been totally digitized but still we prefer some things to be non digitalis ed. The analogue clock is a classic instrument back then and is still classic. Do you guys know that the word clock is derived from Celtic word Clagan and Clocca which means "Bell"? These sound cool right. Clock has been an important invention for mankind for keeping track of time. If you guys want to know more about the clocks then here is the link : http://en.wikipedia.org/wiki/Clock . OK without further delay let us go to our program.
Here is the screen shot of the out put of the program. Enjoy coding....
/*
Programmer: Ashok Kumar Shrestha (ak007)
Program details: Analog clock anticlockwise v1.0 3 april 2013
*/
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<graphics.h>
struct arccoordstype arcinfo,arcinfom,arcinfoh,arcinfod;
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc\\bgi");
int x=getmaxx()/2,y=getmaxy()/2;
char sstr[40],estr[40];
////////////////outer circles//////////////////////////////
setcolor(15);
circle(x,y,200);
circle(x,y,215);
//////////////////numberes in clock////////////////////////
settextstyle(1,0,4);
for(int i=1;i<=12;i++)
{ setcolor(0);
arc(x-20,y-20,(i+2)*30,(i+3)*3,170);
getarccoords(&arcinfod);
setcolor(15);
if(i==1)
sprintf(sstr, "%2d",12);
else
sprintf(sstr, "%2d",i-1);
outtextxy(arcinfod.xstart,arcinfod.ystart, sstr);
}
struct dostime_t t;
while(!kbhit())
{
//////////////////name in clock///////////////////////////
sprintf(estr, "ashok %03d",7);
outtextxy(x-70,y+70, estr);
////////////////get time using dos/////////////////////////
_dos_gettime(&t);
gotoxy(1,1);
printf("\t\t\tThe current time is: %2d:%02d:%02d.%02d\n", t.hour, t.minute,t.second, t.hsecond);
///////////////////second hand///////////////////////////////
setcolor(0);
arc(x,y,(t.second+14)*6,(t.second+15)*6,155);
line(x,y,arcinfo.xend,arcinfo.yend);
getarccoords(&arcinfo);
setcolor(14);
line(x,y,arcinfo.xend,arcinfo.yend);
{
///////////////////////minute hand//////////////////////////
setcolor(0);
line(x,y,arcinfom.xend,arcinfom.yend);
arc(x,y,(t.minute+14)*6,(t.minute+15)*6,125);
getarccoords(&arcinfom);
setcolor(2);
line(x,y,arcinfom.xend,arcinfom.yend);
{
///////////////////////////hour hand/////////////////////////////
setcolor(0);
line(x,y,arcinfoh.xend,arcinfoh.yend);
arc(x,y,((t.hour%12+t.minute/60.0)+2.5)*30,((t.hour%12+t.minute/60.0)+3)*30,90);
getarccoords(&arcinfoh);
setcolor(11);
line(x,y,arcinfoh.xend,arcinfoh.yend);
}
}
delay(100);
}
getch();
}
//End of program
Here is the screen shot of the out put of the program. Enjoy coding....
/*
Programmer: Ashok Kumar Shrestha (ak007)
Program details: Analog clock anticlockwise v1.0 3 april 2013
*/
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<graphics.h>
struct arccoordstype arcinfo,arcinfom,arcinfoh,arcinfod;
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc\\bgi");
int x=getmaxx()/2,y=getmaxy()/2;
char sstr[40],estr[40];
////////////////outer circles//////////////////////////////
setcolor(15);
circle(x,y,200);
circle(x,y,215);
//////////////////numberes in clock////////////////////////
settextstyle(1,0,4);
for(int i=1;i<=12;i++)
{ setcolor(0);
arc(x-20,y-20,(i+2)*30,(i+3)*3,170);
getarccoords(&arcinfod);
setcolor(15);
if(i==1)
sprintf(sstr, "%2d",12);
else
sprintf(sstr, "%2d",i-1);
outtextxy(arcinfod.xstart,arcinfod.ystart, sstr);
}
struct dostime_t t;
while(!kbhit())
{
//////////////////name in clock///////////////////////////
sprintf(estr, "ashok %03d",7);
outtextxy(x-70,y+70, estr);
////////////////get time using dos/////////////////////////
_dos_gettime(&t);
gotoxy(1,1);
printf("\t\t\tThe current time is: %2d:%02d:%02d.%02d\n", t.hour, t.minute,t.second, t.hsecond);
///////////////////second hand///////////////////////////////
setcolor(0);
arc(x,y,(t.second+14)*6,(t.second+15)*6,155);
line(x,y,arcinfo.xend,arcinfo.yend);
getarccoords(&arcinfo);
setcolor(14);
line(x,y,arcinfo.xend,arcinfo.yend);
{
///////////////////////minute hand//////////////////////////
setcolor(0);
line(x,y,arcinfom.xend,arcinfom.yend);
arc(x,y,(t.minute+14)*6,(t.minute+15)*6,125);
getarccoords(&arcinfom);
setcolor(2);
line(x,y,arcinfom.xend,arcinfom.yend);
{
///////////////////////////hour hand/////////////////////////////
setcolor(0);
line(x,y,arcinfoh.xend,arcinfoh.yend);
arc(x,y,((t.hour%12+t.minute/60.0)+2.5)*30,((t.hour%12+t.minute/60.0)+3)*30,90);
getarccoords(&arcinfoh);
setcolor(11);
line(x,y,arcinfoh.xend,arcinfoh.yend);
}
}
delay(100);
}
getch();
}
//End of program
Comments
Post a Comment