Digital and Analog Watch implementation in C

Here a Digital and Analog Implementation in C (Language) i.e the beauty of C. if you really want to implement so try to understand code. before doing this you should have basic knowledge of C programming language. 

Code.
/*
    Author : Mohammad Usman
    Date   : 24/05/2007    
*/
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include<dos.h>
int main(void)
{
   /* Request auto detection */
   int gdriver = DETECT, gmode, errorcode;
   struct time t;
   int midx, midy;
   int radius = 100,i,j,a,a1,m;   
   /* initialize graphics and local variables */
   initgraph(&gdriver, &gmode, "..\\bgi");
   /* read result of initialization */
   errorcode = graphresult();
   if (errorcode != grOk)  /* an error occurred */
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1); /* terminate with an error code */
   }
   midx = getmaxx() / 2;
   midy = getmaxy() / 2;
   setcolor(getmaxcolor());
   setcolor(128);
   for(i=0;;i=i+6)
   {
    setcolor(0);
    gotoxy(40,10);
    puts("12");
    gotoxy(40,20);
    puts("6");
    gotoxy(50,15);
    puts("3");
    gotoxy(31,15);
    puts("9");
    gettime(&t);
    j=t.ti_sec;
    gotoxy(6,3);
    printf("%c  *************************************************************** %2c",3,3);
    gotoxy(20,5);
    printf("%c Welcome To Usman's Digital and Analog Watch%2c",3,3);
    gotoxy(33,7);
    printf("Time is %2d:%2d:%2d",(t.ti_hour),t.ti_min,t.ti_sec);
    a=360-t.ti_sec*6;
    m=360-t.ti_min*6;
    a1=360-t.ti_hour*(30+(t.ti_min/25));       
    pieslice(midx,midy-5,(a)+90,(a)+91,radius-35);      //seconds
    pieslice(midx,midy-5,(a1)+90,(a1)+91,radius-45);    //hours
    pieslice(midx,midy-5,(m)+90,(m)+91,radius-30);       //minuts
    arc(midx,midy-5,a+90,a+91,radius-30);//pointer
       for(i=0;i<=360;i=i+6) //hours
       {
           if(i==6||i==12||i==24||i==30||i==42||i==48||i==60||i==66)
           {
           arc(midx,midy-8,i*5,5*i+1,radius-19);//loop
           }
       }
    circle(midx, midy-8, radius);
    circle(midx, midy-8, radius-10);
    delay(1000);
    clrscr();
    }
   /* clean up */
   getch();
   closegraph();
   return 0;
} 
 

2 comments:

  1. Just want to say your article is as surprising. The clarity in your post is simply excellent and i
    can assume you're an expert on this subject. Well with your permission let me to grab your RSS feed to keep up to date with forthcoming post. Thanks a million and please continue the enjoyable work.
    Feel free to visit my homepage - best registry cleaner

    ReplyDelete

Comment On Facebook