Advertisement
NAHID_GTC

Untitled

Nov 19th, 2023
655
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.89 KB | None | 0 0
  1. #include <GL/gl.h>
  2. #include<stdio.h>
  3. #include<math.h>
  4. #include <GL/glut.h>
  5.  
  6. void init(void)
  7. {
  8.     glClearColor(0.0, 0.9, 0.9, 0.0);
  9.     glMatrixMode(GL_PROJECTION);
  10.     gluOrtho2D(0, 1000, 0, 900);
  11. }
  12.  
  13. void circle(GLfloat rx, GLfloat ry, GLfloat cx, GLfloat cy)
  14. {
  15.     glBegin(GL_POLYGON);
  16.     glVertex2f(cx, cy);
  17.     for (int i = 0; i <= 360; i++)
  18.     {
  19.         float angle = i * 3.1416 / 180;
  20.         float x = rx * cos(angle);
  21.         float y = ry * sin(angle);
  22.         glVertex2f((x + cx), (y + cy));
  23.     }
  24.     glEnd();
  25. }
  26.  
  27. float shift = 0; // a variable used to move the boat right and left
  28.  
  29.  
  30. float bx = 10;
  31.  
  32. void clouds()
  33. {
  34.     glPushMatrix();
  35.     glTranslatef(bx, 0, 0);
  36.     // 1st cloud
  37.     glColor3ub(255, 255, 255);
  38.  
  39.     // first cloud
  40.     circle(50, 50, 300, 700);
  41.     circle(50, 50, 350, 700);
  42.     circle(50, 50, 400, 700);
  43.     circle(50, 50, 450, 700);
  44.  
  45.     circle(50, 50, 325, 725);
  46.     circle(50, 50, 350, 725);
  47.     circle(50, 50, 400, 725);
  48.     circle(50, 50, 425, 725);
  49.  
  50.     circle(50, 50, 345, 750);
  51.     circle(50, 50, 400, 750);
  52.     circle(50, 50, 415, 750);
  53.  
  54.     // seond cloud
  55.     circle(50, 50, 600, 720);
  56.     circle(50, 50, 650, 720);
  57.     circle(50, 50, 700, 720);
  58.     circle(50, 50, 750, 720);
  59.  
  60.     circle(50, 50, 625, 745);
  61.     circle(50, 50, 650, 745);
  62.     circle(50, 50, 700, 745);
  63.     circle(50, 50, 725, 745);
  64.  
  65.     circle(50, 50, 645, 770);
  66.     circle(50, 50, 700, 770);
  67.     circle(50, 50, 715, 770);
  68.  
  69.     // tree
  70.     glColor3f(194.0/255.0, 114.0/255.0, 17.0/255.0);
  71.     glBegin(GL_QUADS);
  72.         glVertex2d(800, 300);
  73.         glVertex2d(800, 600);
  74.         glVertex2d(850, 600);
  75.         glVertex2d(850, 300);
  76.     glEnd();
  77.  
  78.     glColor3ub(0,128,0);
  79.  
  80.     circle(50, 50, 750, 600);
  81.     circle(50, 50, 800, 600);
  82.     circle(50, 50, 850, 600);
  83.     circle(50, 50, 900, 600);
  84.  
  85.     circle(50, 50, 775, 625);
  86.     circle(50, 50, 800, 625);
  87.     circle(50, 50, 850, 625);
  88.     circle(50, 50, 875, 625);
  89.  
  90.     circle(50, 50, 795, 650);
  91.     circle(50, 50, 850, 650);
  92.     circle(50, 50, 855, 650);
  93.    /* glPopMatrix();
  94.     bx += .05;
  95.     if (bx > 0)
  96.         bx = -500;
  97.     glutPostRedisplay();*/
  98.  
  99. }
  100.  
  101. void display(void)
  102. {
  103.     glClear(GL_COLOR_BUFFER_BIT);
  104.  
  105.     // green field
  106.     glColor3f(0,128,0);
  107.     glBegin(GL_QUADS);
  108.         glVertex2d(0, 0);
  109.         glVertex2d(0, 300);
  110.         glVertex2d(1000, 300);
  111.         glVertex2d(1000, 0);
  112.     glEnd();
  113.  
  114.     //sun design
  115.     glColor3f(255, 215, 0);
  116.  
  117.     circle(50, 50, 100, 700);
  118.  
  119.     // clouds design
  120.     clouds();
  121.  
  122.  
  123.     glFlush();
  124.     glutSwapBuffers();
  125. }
  126.  
  127.  
  128. int main(int argc, char** argv)
  129. {
  130.     glutInit(&argc, argv);
  131.     glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  132.     glutInitWindowSize(1000, 900);
  133.     glutInitWindowPosition(100, 100);
  134.     glutCreateWindow("A Moving Boat");
  135.     init();
  136.     glutDisplayFunc(display);
  137.     glutMainLoop();
  138.     return 0;
  139. }
  140.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement