Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GL/gl.h>
- #include<stdio.h>
- #include<math.h>
- #include <GL/glut.h>
- void init(void)
- {
- glClearColor(0.0, 0.9, 0.9, 0.0);
- glMatrixMode(GL_PROJECTION);
- gluOrtho2D(0, 1000, 0, 900);
- }
- void circle(GLfloat rx, GLfloat ry, GLfloat cx, GLfloat cy)
- {
- glBegin(GL_POLYGON);
- glVertex2f(cx, cy);
- for (int i = 0; i <= 360; i++)
- {
- float angle = i * 3.1416 / 180;
- float x = rx * cos(angle);
- float y = ry * sin(angle);
- glVertex2f((x + cx), (y + cy));
- }
- glEnd();
- }
- float shift = 0; // a variable used to move the boat right and left
- float bx = 10;
- void clouds()
- {
- glPushMatrix();
- glTranslatef(bx, 0, 0);
- // 1st cloud
- glColor3ub(255, 255, 255);
- // first cloud
- circle(50, 50, 300, 700);
- circle(50, 50, 350, 700);
- circle(50, 50, 400, 700);
- circle(50, 50, 450, 700);
- circle(50, 50, 325, 725);
- circle(50, 50, 350, 725);
- circle(50, 50, 400, 725);
- circle(50, 50, 425, 725);
- circle(50, 50, 345, 750);
- circle(50, 50, 400, 750);
- circle(50, 50, 415, 750);
- // seond cloud
- circle(50, 50, 600, 720);
- circle(50, 50, 650, 720);
- circle(50, 50, 700, 720);
- circle(50, 50, 750, 720);
- circle(50, 50, 625, 745);
- circle(50, 50, 650, 745);
- circle(50, 50, 700, 745);
- circle(50, 50, 725, 745);
- circle(50, 50, 645, 770);
- circle(50, 50, 700, 770);
- circle(50, 50, 715, 770);
- // tree
- glColor3f(194.0/255.0, 114.0/255.0, 17.0/255.0);
- glBegin(GL_QUADS);
- glVertex2d(800, 300);
- glVertex2d(800, 600);
- glVertex2d(850, 600);
- glVertex2d(850, 300);
- glEnd();
- glColor3ub(0,128,0);
- circle(50, 50, 750, 600);
- circle(50, 50, 800, 600);
- circle(50, 50, 850, 600);
- circle(50, 50, 900, 600);
- circle(50, 50, 775, 625);
- circle(50, 50, 800, 625);
- circle(50, 50, 850, 625);
- circle(50, 50, 875, 625);
- circle(50, 50, 795, 650);
- circle(50, 50, 850, 650);
- circle(50, 50, 855, 650);
- /* glPopMatrix();
- bx += .05;
- if (bx > 0)
- bx = -500;
- glutPostRedisplay();*/
- }
- void display(void)
- {
- glClear(GL_COLOR_BUFFER_BIT);
- // green field
- glColor3f(0,128,0);
- glBegin(GL_QUADS);
- glVertex2d(0, 0);
- glVertex2d(0, 300);
- glVertex2d(1000, 300);
- glVertex2d(1000, 0);
- glEnd();
- //sun design
- glColor3f(255, 215, 0);
- circle(50, 50, 100, 700);
- // clouds design
- clouds();
- glFlush();
- glutSwapBuffers();
- }
- int main(int argc, char** argv)
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
- glutInitWindowSize(1000, 900);
- glutInitWindowPosition(100, 100);
- glutCreateWindow("A Moving Boat");
- init();
- glutDisplayFunc(display);
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement