Saturday, 20 September 2014

WAP to display colorfull watch with running state.

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
#include<dos.h>

void arrow(float a,float b,float c,float d,float e)
{
  float l=44.0/(60.0*7);
  for(;l>0;l-=0.001)
  {
   line(a,b,a+85*cos(e+l),b+85*sin(e+l));
   line(a,b,a+85*cos(e-l),b+85*sin(e-l));
   line(a+85*cos(e+l),b+85*sin(e+l),c,d);
   line(a+85*cos(e-l),b+85*sin(e-l),c,d);
  }
}

void main()
{
  struct time t;
  float a,c,d,e,f,g,h,i,j;
  int gdriver = DETECT, gmode, errorcode;
  initgraph(&gdriver, &gmode, "C:\\turboc3\\bgi");
  setcolor(23);
  gettime(&t);
  c=44.0/7;
  d=c/60;
  e=d/60;
  f=e/12;
  g=((c*t.ti_min/60.0)+(c*t.ti_sec/3600))-11.0/7.0;
  if(t.ti_hour>12)
  h=((c*(t.ti_hour-12.0)/12.0)+(c*t.ti_min/(12.0*60.0)))-11.0/7.0;
  else
  h=((c*t.ti_hour/12.0)+(c*t.ti_min/(60.0*12.0)))-11.0/7.0;
  i=getmaxx()/2;
  j=getmaxy()/2;
  setcolor(5);  a=140;
  setfillstyle(1,5);
  fillellipse(i,j,a,a);
  setcolor(23);
  for (a=0;a<=c;a+=c/12)
  {
   outtextxy(getmaxx()/2+120*cos(a),getmaxy()/2+120*sin(a),"o");
  }
  setcolor(7);
  for(a=140;a<=160;a+=5)
  circle(i,j,a);
  a=(c*t.ti_sec/60.0)-(11.0/7.0);
  for(;;)
  {
    setcolor(5);
    arrow(i,j,i+100*cos(a),j+100*sin(a),a);
    setcolor(1);
    arrow(i,j,i+100*cos(a+d),j+100*sin(a+d),a+d);
    setcolor(5);
    arrow(i/*+30*cos(g)*/,j/*+30*sin(g)*/,i+100*cos(g),j+100*sin(g),g);
    setcolor(4);
    arrow(i/*+30*cos(g+e)*/,j/*+30*sin(g+e)*/,i+100*cos(g+e),j+100*sin(g+e),g+e);
    setcolor(5);
    arrow(i/*+50*cos(h)*/,j/*+50*sin(h)*/,i+100*cos(h),j+100*sin(h),h);
    setcolor(3);
    arrow(i/*+50*cos(h+f)*/,j/*+50*sin(h+f)*/,i+100*cos(h+f),j+100*sin(h+f),h+f);
    delay(1000);
    g=g+e;
    h=h+f;
    a+=d;
    if(kbhit()){
    break;
  }
 }
  getch();
}

No comments:

Post a Comment

Please write your doubts