#include "stdio.h"
#include "conio.h"
#include "graphics.h"
#include "dos.h"
void clear(int,int,int,int);
void main()
{
int gd = DETECT,gm,hour,min,sec,midx,midy,temp;
char buffer[20],ch;
struct time now;
initgraph(&gd,&gm,"c:\\tc\\bgi");
midx = getmaxx()/2;
midy = getmaxy()/2;
setcolor(RED);
rectangle(midx-210,midy-40,midx+198,midy+30);
outtextxy(midx-80,midy+190,"Press \"ESC\" to Exit");
gettime(&now);
if(now.ti_hour > 12)
{
setcolor(GREEN);
settextstyle(5,HORIZ_DIR,5);
outtextxy(midx+170,midy-20,"PM");
hour = now.ti_hour - 12;
ch = 'p';
}
else
{
setcolor(GREEN);
settextstyle(5,HORIZ_DIR,5);
outtextxy(midx+170,midy-20,"AM");
hour = now.ti_hour;
ch = 'a';
}
min = now.ti_min;
sec = now.ti_sec;
while(1)
{
if(kbhit())
{
if(getch() == 27)
break;
}
if(hour == 12 && min == 0 && sec == 0 && ch == 'a')
{
setcolor(BLACK);
settextstyle(5,HORIZ_DIR,5);
outtextxy(midx+170,midy-20,"AM");
setcolor(GREEN);
outtextxy(midx+170,midy-20,"PM");
}
if(hour == 12 && min == 0 && sec == 0 && ch == 'p')
{
setcolor(BLACK);
settextstyle(5,HORIZ_DIR,5);
outtextxy(midx+170,midy-20,"PM"); /* To Overwrite Previous Notation */
setcolor(GREEN);
outtextxy(midx+170,midy-20,"AM");
}
delay(1000);
if(sec >= 59)
{
clear(midx-12,midy-32,midx+32,midy+25);
min++;
if(min > 59)
{
min = 0;
hour++;
if(hour > 12)
hour -= 12;
clear(midx-144,midy-32,midx-101,midy+25);
if(hour > 9)
{
clear(midx-144,midy-32,midx-101,midy+25);
clear(midx-198,midy-32,midx-156,midy+25);
}
}
if(min%10 == 0)
clear(midx-67,midy-32,midx-25,midy+25);
sec = 0;
}
else
sec++;
if(sec%10 == 0)
clear(midx+65,midy-32,midx+107,midy+25);
clear(midx+120,midy-32,midx+162,midy+25); /* To clear seconds */
sprintf(buffer,"%02d:%02d:%02d",hour,min,sec);
setcolor(BROWN);
settextstyle(5,HORIZ_DIR,8);
outtextxy(midx-195,midy-70,buffer);
}
closegraph();
}
/* This function clears the specified area */
/* by glowing the pixel of that area in black color */
void clear(int x1,int y1,int x2,int y2)
{
int x,y;
for(x=x1;x<=x2;x++)
for(y=y1;y<=y2;y++)
putpixel(x,y,BLACK);
}
Friday, September 4, 2009
A DIGITAL WATCH
Labels: c graphics, Nice Programs
Posted by Unknown at 1:07 AM
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment