//digital_clock
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void main()
{
int gd = DETECT, gm;
int i=0, a[5];
struct time t;
initgraph(&gd, &gm, "c:\\tc\\bgi"); //Initializing Graphics mode
while(!kbhit()) // if key hit is not received, display the clock
{
setcolor(YELLOW);
gettime(&t);
if(t.ti_hour>12)
{
t.ti_hour = t.ti_hour-12;
settextstyle(DEFAULT_FONT,0,4);
outtextxy(550,150,"PM");
}
else
{
outtextxy(550,150,"AM");
}
a[0]=t.ti_hour/10;
a[1]=t.ti_hour%10;
a[2]=t.ti_min/10;
a[3]=t.ti_min%10;
a[4]=t.ti_sec/10;
a[5]=t.ti_sec%10;
circle(240,150,2);
circle(240,160,2);
circle(390,150,2);
circle(390,160,2);
for(i=0;i<6;i++)
{
switch(a[i]) //Out the particular digit according to the input//
{
case 0:
{
line(105+i*75,100,145+i*75,100);
line(100+i*75,105,100+i*75,145);
line(100+i*75,155,100+i*75,195);
line(105+i*75,200,145+i*75,200);
line(150+i*75,155,150+i*75,195);
line(150+i*75,105,150+i*75,145);
break;
}
case 1:
{
line(150+i*75,155,150+i*75,195);
line(150+i*75,105,150+i*75,145);
break;
}
case 2:
{
line(105+i*75,100,145+i*75,100);
line(100+i*75,155,100+i*75,195);
line(105+i*75,200,145+i*75,200);
line(150+i*75,105,150+i*75,145);
line(105+i*75,150,145+i*75,150);
break;
}
case 3:
{
line(105+i*75,100,145+i*75,100);
line(105+i*75,200,145+i*75,200);
line(150+i*75,155,150+i*75,195);
line(150+i*75,105,150+i*75,145);
line(105+i*75,150,145+i*75,150);
break;
}
case 4:
{
line(100+i*75,105,100+i*75,145);
line(150+i*75,155,150+i*75,195);
line(150+i*75,105,150+i*75,145);
line(105+i*75,150,145+i*75,150);
break;
}
case 5:
{
line(105+i*75,100,145+i*75,100);
line(100+i*75,105,100+i*75,145);
line(105+i*75,200,145+i*75,200);
line(150+i*75,155,150+i*75,195);
line(105+i*75,150,145+i*75,150);
break;
}
case 6:
{
line(105+i*75,100,145+i*75,100);
line(100+i*75,105,100+i*75,145);
line(100+i*75,155,100+i*75,195);
line(105+i*75,200,145+i*75,200);
line(150+i*75,155,150+i*75,195);
line(105+i*75,150,145+i*75,150);
break;
}
case 7:
{
line(105+i*75,100,145+i*75,100);
line(150+i*75,155,150+i*75,195);
line(150+i*75,105,150+i*75,145);
break;
}
case 8:
{
line(105+i*75,100,145+i*75,100);
line(100+i*75,105,100+i*75,145);
line(100+i*75,155,100+i*75,195);
line(105+i*75,200,145+i*75,200);
line(150+i*75,155,150+i*75,195);
line(150+i*75,105,150+i*75,145);
line(105+i*75,150,145+i*75,150);
break;
}
case 9:
{
line(105+i*75,100,145+i*75,100);
line(100+i*75,105,100+i*75,145);
line(105+i*75,200,145+i*75,200);
line(150+i*75,155,150+i*75,195);
line(150+i*75,105,150+i*75,145);
line(105+i*75,150,145+i*75,150);
break;
}
}
}
delay(700);
cleardevice();
}
closegraph();
}
No comments:
Post a Comment