Analogue Clock clockwise: Using C and Graphics
Here's the analogue clock that runs clock wise direction. Hope you guys like it. Here's the screen shot of the output.
Let's us see the code. The code is very much similar to the previous program that I have posted i.e. analogue clock which rotates in anti clockwise direction. Enjoy coding...
/*
Programmer: Ashok Kumar Shrestha ak(007)
Program details: analog clock clockwise 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=12;i>=1;i--)
{ setcolor(0);
arc(x-20,y-20,(12-i+4)*30,(12-i+5)*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);
arc(x,y,90,90+(360-t.second*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);
arc(x,y,90,90+(360-t.minute*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);
arc(x,y,90,90+(360-((t.hour)%12+t.minute/60.0)*30),90);
getarccoords(&arcinfoh);
setcolor(11);
line(x,y,arcinfoh.xend,arcinfoh.yend);
}
}
delay(100);
}
getch();
}
//End of the program
Let's us see the code. The code is very much similar to the previous program that I have posted i.e. analogue clock which rotates in anti clockwise direction. Enjoy coding...
/*
Programmer: Ashok Kumar Shrestha ak(007)
Program details: analog clock clockwise 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=12;i>=1;i--)
{ setcolor(0);
arc(x-20,y-20,(12-i+4)*30,(12-i+5)*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);
arc(x,y,90,90+(360-t.second*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);
arc(x,y,90,90+(360-t.minute*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);
arc(x,y,90,90+(360-((t.hour)%12+t.minute/60.0)*30),90);
getarccoords(&arcinfoh);
setcolor(11);
line(x,y,arcinfoh.xend,arcinfoh.yend);
}
}
delay(100);
}
getch();
}
//End of the program
Comments
Post a Comment