Ridwanul_Haque

CLOCK_iGraphics

May 26th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.26 KB | None | 0 0
  1. #include "iGraphics.h"
  2. #include<stdio.h>
  3. #include<math.h>
  4.  
  5. int x = 300, y = 300, r = 20, s1=300, s2=490,m1=300,m2=485,h1=300,h2=480;
  6. double angle1=0,angle2=0,angle3=0;
  7. int hour,minute,second;
  8. char n;
  9. /*
  10.     function iDraw() is called again and again by the system.
  11.  
  12.     */
  13. void secondhand()
  14.     {
  15.        angle1 +=.1047197551;
  16.     }
  17. void minutehand()
  18.     {
  19.     angle2 +=.1047197551;
  20.     }
  21.  
  22. void hourhand()
  23.     {
  24.        angle3 +=.1047197551;
  25.     }
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33. void iDraw() {
  34.     //place your drawing codes here
  35.     iClear();
  36.  
  37.     int h1=300+160*(sin(0.5235987756*hour+0.008726646*minute+angle3));
  38.     int h2=300+160*(cos(0.5235987756*hour+0.008726646*minute+angle3));
  39.     int m1=300+180*(sin(0.1047197551*minute+angle2));
  40.     int m2=300+180*(cos(0.1047197551*minute+angle2));
  41.     int s1=300+185*(sin(0.1047197551*second+angle1));
  42.     int s2=300+185*(cos(0.1047197551*second+angle1));
  43.  
  44.     iSetColor(300,123,500);
  45.     iText(250,600,"Second Hand");
  46.     iSetColor(255,255,255);
  47.     iText(250,580,"Minute Hand");
  48.     iSetColor(0,206,209);
  49.     iText(250,560,"Hour Hand");
  50.  
  51.     iSetColor(12,171,7);
  52.     iFilledCircle(300,300,7);
  53.     iSetColor(182,0,73);
  54.     iCircle(300,300,220,300);
  55.  
  56.  
  57.  
  58.     iSetColor(0,128,128);
  59.     iCircle(300, 300, 190,300);
  60.     //iFilledRectangle(10, 30, 20, 20);
  61.     iSetColor(20, 200, 0);
  62.     iText(200, 37, "Analog Clock by RIDWANUL HAQUE");
  63.     iSetColor(0,255,255);
  64.     iRectangle(50,50,500,500);
  65.     iSetColor(300,123,500);
  66.     iLine(300,300,s1,s2);
  67.     iSetColor(255,255,255);
  68.     iLine(300,300,m1,m2);
  69.     iSetColor(0,206,209);
  70.     iLine(300,300,h1,h2);
  71.  
  72.  
  73.     iSetColor(400,400,0);
  74.     iText(292,500,"12");
  75.     iText(500,300,"3");
  76.     iText(296,95,"6");
  77.     iText(95,296,"9");
  78.     iText(394,473.2,"1");
  79.     iText(193,473.2,"11");
  80.     iText(471.2,400,"2");
  81.     iText(118.8,400,"10");
  82.     iText(473.2,197,"4");
  83.     iText(400,120.8,"5");
  84.     iText(116.8,198,"8");
  85.     iText(188,120.8,"7");
  86. }
  87.  
  88. /*
  89.     function iMouseMove() is called when the user presses and drags the mouse.
  90.     (mx, my) is the position where the mouse pointer is.
  91.     */
  92. void iMouseMove(int mx, int my) {
  93.     printf("x = %d, y= %d\n",mx,my);
  94.     //place your codes here
  95. }
  96.  
  97. /*
  98.     function iMouse() is called when the user presses/releases the mouse.
  99.     (mx, my) is the position where the mouse pointer is.
  100.     */
  101. void iMouse(int button, int state, int mx, int my) {
  102.     if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
  103.         //place your codes here
  104.         printf("x = %d, y= %d\n",mx,my);
  105.         x += 10;
  106.         y += 10;
  107.     }
  108.     if (button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN) {
  109.         //place your codes here
  110.         x -= 10;
  111.         y -= 10;
  112.     }
  113. }
  114.  
  115. /*
  116.     function iKeyboard() is called whenever the user hits a key in keyboard.
  117.     key- holds the ASCII value of the key pressed.
  118.     */
  119. void iKeyboard(unsigned char key) {
  120.     if (key == 'q') {
  121.         exit(0);
  122.     }
  123.     //place your codes for other keys here
  124. }
  125.  
  126. /*
  127.     function iSpecialKeyboard() is called whenver user hits special keys like-
  128.     function keys, home, end, pg up, pg down, arraows etc. you have to use
  129.     appropriate constants to detect them. A list is:
  130.     GLUT_KEY_F1, GLUT_KEY_F2, GLUT_KEY_F3, GLUT_KEY_F4, GLUT_KEY_F5, GLUT_KEY_F6,
  131.     GLUT_KEY_F7, GLUT_KEY_F8, GLUT_KEY_F9, GLUT_KEY_F10, GLUT_KEY_F11, GLUT_KEY_F12,
  132.     GLUT_KEY_LEFT, GLUT_KEY_UP, GLUT_KEY_RIGHT, GLUT_KEY_DOWN, GLUT_KEY_PAGE UP,
  133.     GLUT_KEY_PAGE DOWN, GLUT_KEY_HOME, GLUT_KEY_END, GLUT_KEY_INSERT
  134.     */
  135. void iSpecialKeyboard(unsigned char key) {
  136.  
  137.     if (key == GLUT_KEY_END) {
  138.         exit(0);
  139.     }
  140.     //place your codes for other keys here
  141. }
  142.  
  143.  
  144. int main() {
  145.     //place your own initialization codes here.
  146.     printf("Do you want to see the current time ? (Y/N)\n>>>");
  147.     scanf("%c",&n);
  148.     switch(n)
  149.     {
  150.     case 'Y':
  151.     {
  152.     time_t now;
  153.     struct tm *timeinfo;
  154.     time(&now);
  155.     timeinfo=localtime(&now);
  156.     hour=timeinfo->tm_hour;
  157.     hour=hour%12;
  158.     minute=timeinfo->tm_min;
  159.     second=timeinfo->tm_sec;
  160.  
  161.     iSetTimer(1000,secondhand);
  162.     iSetTimer(60000,minutehand);
  163.     iSetTimer(720000,hourhand);
  164.     iInitialize(601, 701, "CLOCK_RIDY");
  165.     break;
  166.  
  167.     }
  168.     case 'N':
  169.     {
  170.  
  171.     printf("Enter the hour = ");
  172.     scanf("%d",&hour);
  173.     printf("Enter the minute = ");
  174.     scanf("%d",&minute);
  175.     printf("Enter the second = ");
  176.     scanf("%d",&second);
  177.  
  178.     iSetTimer(1000,secondhand);
  179.     iSetTimer(60000,minutehand);
  180.     iSetTimer(720000,hourhand);
  181.     iInitialize(601, 701, "CLOCK_RIDY");
  182.     break;
  183.  
  184.     }
  185.  
  186.     return 0;
  187.     }
  188. }
Add Comment
Please, Sign In to add comment