Advertisement
mouhsineelachbi

Dessiner une montre avec C_By Mouhsine_ELACHBI

Mar 5th, 2016
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.63 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<graphics.h>
  3. #include<stdlib.h>
  4. #include<math.h>
  5. #include<dos.h>
  6. #include<time.h>
  7.  
  8. #define PI 3.147
  9.  
  10. void clockLayout();
  11. void secHand();
  12. void hrHand();
  13. void minHand();
  14. int maxx,maxy;
  15.  
  16. void main()
  17. {
  18.  int gdriver=DETECT,gmode,error;
  19.  initgraph(&gdriver,&gmode,"c:\turboc3\bgi\");
  20. error=graphresult();
  21. if(error!=grOk)
  22. {
  23.  printf("Error in graphics, code= %d",grapherrormsg(error));
  24.  exit(0);
  25. }
  26.  
  27. while(1)
  28. {
  29.  clockLayout();
  30.  secHand();
  31.  minHand();
  32.  hrHand();
  33.  sleep(1);                /* pausing the outputscreen for 1 sec */
  34.  cleardevice();           /* clearing the previous picture of clock */
  35. }
  36. }
  37.  
  38. void clockLayout()
  39. {
  40. int i,x,y,r;
  41. float j;
  42. maxx=getmaxx();
  43. maxy=getmaxy();
  44.  
  45. for(i=1;i<5;i++)
  46. {                   /* printing a round ring with outer radius of 5 pixel */
  47.  setcolor(YELLOW);
  48.  circle(maxx/2,maxy/2,120-i);
  49. }
  50.  
  51. pieslice(maxx/2,maxy/2,0,360,5);    /* displaying a circle in the middle of clock */
  52. x=maxx/2+100;y=maxy/2;
  53. r=100;
  54. setcolor(BLUE);
  55.  
  56. for(j=PI/6;j<=(2*PI);j+=(PI/6))
  57. {    /* marking the hours for every 30 degrees */
  58.  pieslice(x,y,0,360,4);
  59.  x=(maxx/2)+r*cos(j);
  60.  y=(maxy/2)+r*sin(j);
  61. }
  62.  
  63. x=maxx/2+100;y=maxy/2;
  64. r=100;
  65. setcolor(RED);
  66.  
  67. for(j=PI/30;j<=(2*PI);j+=(PI/30))
  68. {  /* marking the minutes for every 6 degrees */
  69.  pieslice(x,y,0,360,2);
  70.  x=(maxx/2)+r*cos(j);
  71.  y=(maxy/2)+r*sin(j);
  72. }
  73. }
  74.  
  75. void secHand()
  76. {
  77. struct time t;
  78. int r=80,x=maxx/2,y=maxy/2,sec;
  79. float O;
  80.  
  81. maxx=getmaxx();maxy=getmaxy();
  82. gettime(&t);                     /*getting the seconds in system clock */
  83. sec=t.ti_sec;
  84. O=sec*(PI/30)-(PI/2);           /* determining the angle of the line with respect to vertical */
  85. setcolor(YELLOW);
  86. line(maxx/2,maxy/2,x+r*cos(O),y+r*sin(O));
  87. }
  88.  
  89. void hrHand()
  90. {
  91. int r=50,hr,min;
  92. int x,y;
  93. struct time t;
  94. float O;
  95.  
  96. maxx=getmaxx();
  97. maxy=getmaxy();
  98. x=maxx/2,y=maxy/2;
  99. gettime(&t);                     /*getting the seconds in system clock */
  100. hr=t.ti_hour;
  101. min=t.ti_min;
  102.  
  103. /* determining the angle of the line with respect to vertical */
  104. if(hr<=12)O=(hr*(PI/6)-(PI/2))+((min/12)*(PI/30));
  105. if(hr>12) O=((hr-12)*(PI/6)-(PI/2))+((min/12)*(PI/30));
  106. setcolor(BLUE);
  107. line(maxx/2,maxy/2,x+r*cos(O),y+r*sin(O));
  108. }
  109.  
  110. void minHand()
  111. {
  112. int r=60,min;
  113. int x,y;
  114. float O;
  115. struct time t;
  116. maxx=getmaxx();
  117. maxy=getmaxy();
  118. x=maxx/2;
  119. y=maxy/2;
  120. gettime(&t);  /*getting the seconds in system clock */
  121. min=t.ti_min;
  122. O=(min*(PI/30)-(PI/2)); /* determining the angle of the line with respect to vertical */
  123. setcolor(RED);
  124. line(maxx/2,maxy/2,x+r*cos(O),y+r*sin(O));
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement