NAHID_GTC

Untitled

Nov 5th, 2023
640
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.87 KB | None | 0 0
  1. #include<windows.h>
  2. #include <GL/glut.h>
  3. #include <iostream>
  4. using namespace std;
  5. bool state = true;
  6. float x = 0.0, y = 100.0;
  7. void init(void)
  8. {
  9.     glClearColor(0.0, 0.0, 0.0, 0.0);
  10.  
  11.     glMatrixMode(GL_PROJECTION);
  12.  
  13.     gluOrtho2D(0.0, 800.0, 0.0, 800.0);
  14. }
  15.  
  16. void drawShapes(void)
  17. {
  18.     glClear(GL_COLOR_BUFFER_BIT);
  19.  
  20.     cout << x << " " << y << " " << int(state) << endl;
  21.  
  22.  
  23.     if(state)
  24.     {
  25.         if(x < 700 || y < 700)
  26.         {
  27.             x += 0.1;
  28.             y += 0.1;
  29.         }
  30.         else
  31.         {
  32.             state = false;
  33.         }
  34.     }
  35.     else
  36.     {
  37.         if(x > 0 || y > 100)
  38.         {
  39.             x -= 0.1;
  40.             y -= 0.1;
  41.         }
  42.         else
  43.         {
  44.             state = true;
  45.         }
  46.     }
  47.  
  48.  
  49.     glColor3f(1.0, 1.0, 1.0);
  50.     glBegin(GL_QUADS);
  51.         glVertex2i(x, y);
  52.         glVertex2i(x+100, y);
  53.         glVertex2i(x+100, y-100);
  54.         glVertex2i(x, y-100);
  55.     glEnd();
  56.  
  57.     glColor3f(1.0, 0.0, 0.0);
  58.     glBegin(GL_QUADS);
  59.         glVertex2i(x, 200);
  60.         glVertex2i(x+100, 200);
  61.         glVertex2i(x+100, 100);
  62.         glVertex2i(x, 100);
  63.     glEnd();
  64.  
  65.     glColor3f(0.0, 0.0, 1.0);
  66.     glBegin(GL_QUADS);
  67.         glVertex2i(100, y);
  68.         glVertex2i(200, y);
  69.         glVertex2i(200, y-100);
  70.         glVertex2i(100, y-100);
  71.     glEnd();
  72.  
  73.     glutPostRedisplay();
  74.  
  75. glFlush();
  76.  
  77. }
  78. int main(int argc, char* argv[])
  79. {
  80.  
  81.     glutInit(&argc, argv);
  82.     glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
  83.  
  84.     glutInitWindowPosition(1200, 100);
  85.     glutInitWindowSize(900, 900);
  86.     glutCreateWindow("Four Stars");
  87.  
  88.     init();
  89.     glutDisplayFunc(drawShapes);
  90.  
  91.  
  92.     glutMainLoop();
  93.  
  94.     return 0;
  95. }
  96.  
  97.  
  98. /*  cout << x << endl;
  99.     if(!state)
  100.     {
  101.         x += 0.1;
  102.         if(x > 750)
  103.         {
  104.             state != state;
  105.         }
  106.     }
  107.     else
  108.     {
  109.         x -= 0.1;
  110.         if(x <= 1) state != state;
  111.     }
  112. */
  113.  
Advertisement
Add Comment
Please, Sign In to add comment