Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

// Cpmputer Graphics. Add Day (D) & night(N) View in this following code #include #include #include #define PI 3.1416 GLfloat position = 0.0f; GLfloat speed

// Cpmputer Graphics. Add Day (D) & night(N) View in this following code

#include
#include
#include
#define PI 3.1416


GLfloat position = 0.0f;
GLfloat speed = 0.051f;
GLfloat position1 = 0.0f;
GLfloat speed1 = 0.06f;
void dis();
void display();


void update(int value) {

if(position >1.0)
position = -1.0f;

position += speed;

glutPostRedisplay();


glutTimerFunc(100, update, 0);
}

void update1(int value) {

if(position1 <-1.0)
position1 = 1.0f;

position1 -= speed1;

glutPostRedisplay();


glutTimerFunc(100, update1, 0);
}
GLfloat i = 0.0f;


void Idle()
{
glutPostRedisplay();
}

void SpecialInput(int key, int x, int y)
{
switch(key)
{
case GLUT_KEY_UP:
speed1 = 0.05f;
glutTimerFunc(100, update1, 0);
break;
case GLUT_KEY_DOWN:
speed1 = 0.0f;
glutTimerFunc(100, update, 0);
break;
case GLUT_KEY_LEFT:
speed = 0.05f;
break;
case GLUT_KEY_RIGHT:
speed = 0.0f;
break;
}
glutPostRedisplay();
}
void init() {
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
}

void display3()
{
glClearColor(0.0f,0.0f,0.0f,1.0f);
glClear(GL_COLOR_BUFFER_BIT);

glBegin(GL_QUADS);   //Background color
glColor3ub(2, 0, 9);
glVertex2f(1.0f,-1.0f);
glVertex2f(1.0f,1.0f);
glVertex2f(-1.0f,1.0f);
glVertex2f(-1.0f,-1.0f);
glEnd();

glLineWidth(4.5);   //wind mill
glBegin(GL_LINES);
glColor3ub(244, 4, 62);
glVertex2f(0.6f,0.1f);
glVertex2f(0.6f,0.6f);
glEnd();

glPushMatrix();
glTranslatef(0.6f,0.6f,0.0f);
glRotatef(i,0,0.0,0.1);

glBegin(GL_TRIANGLES);
glColor3ub(210, 159, 28);
glVertex2f(0.0f,0.0f);
glVertex2f(0.1f,0.2f);
glVertex2f(0.2f,0.15f);
glEnd();

glBegin(GL_TRIANGLES);
glColor3ub(210, 159, 28);
glVertex2f(0.0f,0.0f);
glVertex2f(-0.1f,0.2f);
glVertex2f(-0.2f,0.15f);
glEnd();

glBegin(GL_TRIANGLES);
glColor3ub(210, 159, 28);
glVertex2f(0.0f,0.0f);
glVertex2f(0.1f,-0.2f);
glVertex2f(0.0f,-0.2f);
glEnd();
glPopMatrix();
i+=0.1f;

glTranslatef(0.0f,-0.3f,0.0f); //Rail lines
glLineWidth(4.5);
glBegin(GL_LINES);
glColor3ub(84,76,72);
glVertex2f(-1.0f,-0.60f);
glVertex2f(1.0f,-0.60f);
glEnd();

glLineWidth(4.5);
glBegin(GL_LINES);
glColor3ub(84,76,72);
glVertex2f(-1.0f,-0.5f);
glVertex2f(1.0f,-0.5f);
glEnd();


glLineWidth(2);
glBegin(GL_LINES);
glColor3ub(150,70,27);
glVertex2f(-0.95f,-0.60f);
glVertex2f(-0.85f,-0.5f);
glEnd();

glLineWidth(2);
glBegin(GL_LINES);
glColor3ub(150,70,27);
glVertex2f(-0.85f,-0.60f);
glVertex2f(-0.75f,-0.5f);
glEnd();

glLineWidth(2);
glBegin(GL_LINES);
glColor3ub(150,70,27);
glVertex2f(-0.75f,-0.60f);
glVertex2f(-0.65f,-0.5f);
glEnd();

glLineWidth(2);
glBegin(GL_LINES);
glColor3ub(150,70,27);
glVertex2f(-0.65f,-0.60f);
glVertex2f(-0.55f,-0.5f);
glEnd();

glLineWidth(2);
glBegin(GL_LINES);
glColor3ub(150,70,27);
glVertex2f(-0.55f,-0.60f);
glVertex2f(-0.45f,-0.5f);
glEnd();

glLineWidth(2);
glBegin(GL_LINES);
glColor3ub(150,70,27);
glVertex2f(-0.45f,-0.60f);
glVertex2f(-0.35f,-0.5f);
glEnd();

glLineWidth(2);
glBegin(GL_LINES);
glColor3ub(150,70,27);
glVertex2f(-0.35f,-0.60f);
glVertex2f(-0.25f,-0.5f);
glEnd();

glLineWidth(2);
glBegin(GL_LINES);
glColor3ub(150,70,27);
glVertex2f(-0.25f,-0.60f);
glVertex2f(-0.15f,-0.5f);
glEnd();

glLineWidth(2);
glBegin(GL_LINES);
glColor3ub(150,70,27);
glVertex2f(-0.15f,-0.60f);
glVertex2f(-0.05f,-0.5f);
glEnd();

glLineWidth(2);
glBegin(GL_LINES);
glColor3ub(150,70,27);
glVertex2f(-0.05f,-0.60f);
glVertex2f(0.05f,-0.5f);
glEnd();

glLineWidth(2);
glBegin(GL_LINES);
glColor3ub(150,70,27);
glVertex2f(0.05f,-0.60f);
glVertex2f(0.15f,-0.5f);
glEnd();

glLineWidth(2);
glBegin(GL_LINES);
glColor3ub(150,70,27);
glVertex2f(0.15f,-0.60f);
glVertex2f(0.25f,-0.5f);
glEnd();

glLineWidth(2);
glBegin(GL_LINES);
glColor3ub(150,70,27);
glVertex2f(0.25f,-0.60f);
glVertex2f(0.35f,-0.5f);
glEnd();

glLineWidth(2);
glBegin(GL_LINES);
glColor3ub(150,70,27);
glVertex2f(0.25f,-0.60f);
glVertex2f(0.35f,-0.5f);
glEnd();

glLineWidth(2);
glBegin(GL_LINES);
glColor3ub(150,70,27);
glVertex2f(0.35f,-0.60f);
glVertex2f(0.45f,-0.5f);
glEnd();

glLineWidth(2);
glBegin(GL_LINES);
glColor3ub(150,70,27);
glVertex2f(0.45f,-0.60f);
glVertex2f(0.55f,-0.5f);
glEnd();

glLineWidth(2);
glBegin(GL_LINES);
glColor3ub(150,70,27);
glVertex2f(0.55f,-0.60f);
glVertex2f(0.65f,-0.5f);
glEnd();

glLineWidth(2);
glBegin(GL_LINES);
glColor3ub(150,70,27);
glVertex2f(0.65f,-0.60f);
glVertex2f(0.75f,-0.5f);
glEnd();

glLineWidth(2);
glBegin(GL_LINES);
glColor3ub(150,70,27);
glVertex2f(0.75f,-0.60f);
glVertex2f(0.85f,-0.5f);
glEnd();

glLineWidth(2);
glBegin(GL_LINES);
glColor3ub(150,70,27);
glVertex2f(0.85f,-0.60f);
glVertex2f(0.95f,-0.5f);
glEnd();

glLoadIdentity();     //Train
glTranslatef(-0.45f,-0.45f,0.0f);
glScalef(.75,.75,0);
glPushMatrix();
glTranslatef(position,0.0f, 0.0f);
glBegin(GL_TRIANGLES);
glColor3ub(25,38,166);
glVertex2f(0.95f,-0.5f);
glVertex2f(0.8f,-0.5f);
glVertex2f(0.8f,-0.2f);
glEnd();

glBegin(GL_QUADS);
glColor3ub(140,166,25);
glVertex2f(0.8f,-0.2f);
glVertex2f(0.5f,-0.2f);
glVertex2f(0.5f,-0.5f);
glVertex2f(0.8f,-0.5f);
glEnd();

glBegin(GL_QUADS);
glColor3ub(40,166,250);
glVertex2f(0.5f,-0.5f);
glVertex2f(0.2f,-0.5f);
glVertex2f(0.2f,-0.0f);
glVertex2f(0.5f,-0.0f);
glEnd();

glBegin(GL_QUADS);
glColor3ub(249, 239, 4);
glVertex2f(0.4f,-0.4f);
glVertex2f(0.3f,-0.4f);
glVertex2f(0.3f,-0.1f);
glVertex2f(0.4f,-0.1f);
glEnd();

glBegin(GL_QUADS);
glColor3ub(249, 239, 4);
glVertex2f(0.1f,-0.5f);
glVertex2f(-0.4f,-0.5f);
glVertex2f(-0.4f,-0.2f);
glVertex2f(0.1f,-0.2f);
glEnd();

glBegin(GL_QUADS);
glColor3ub(249, 239, 4);
glVertex2f(-0.5f,-0.5f);
glVertex2f(-0.95f,-0.5f);
glVertex2f(-0.95f,-0.2f);
glVertex2f(-0.5f,-0.2f);
glEnd();

glLineWidth(7.5);
glBegin(GL_LINES);
glColor3ub(245,246,250);
glVertex2f(-0.5f,-0.45f);
glVertex2f(-0.4f,-0.45f);
glEnd();
glLineWidth(7.5);
glBegin(GL_LINES);
glColor3ub(240,240,240);
glVertex2f(0.2f,-0.45f);
glVertex2f(0.1f,-0.45f);
glEnd();

GLfloat    x=0.75f;     //Train wheel
GLfloat y=-0.5f;
GLfloat radius= 0.1f;
int   i;
int triangleAmount=30;
GLfloat twicepi = 2.0f*PI;
glBegin(GL_TRIANGLE_FAN);
glColor3ub(171,22,17);
for(i=0;i<=triangleAmount;i++){
glVertex2f(
x+(radius*cos(i*twicepi/triangleAmount)),
y+(radius*sin(i*twicepi/triangleAmount))
);

};
glEnd();

x=0.35f;
y=-0.5f;
radius= 0.1f;
i;
triangleAmount=30;
//GLfloat twicepi = 2.0f*PI;
glBegin(GL_TRIANGLE_FAN);
glColor3ub(171,22,17);
for(i=0;i<=triangleAmount;i++){
glVertex2f(
x+(radius*cos(i*twicepi/triangleAmount)),
y+(radius*sin(i*twicepi/triangleAmount))
);

};
glEnd();


x=-0.0f;
y=-0.5f;
radius= 0.1f;
i;
triangleAmount=30;
//GLfloat twicepi = 2.0f*PI;
glBegin(GL_TRIANGLE_FAN);
glColor3ub(171,22,17);
for(i=0;i<=triangleAmount;i++){
glVertex2f(
x+(radius*cos(i*twicepi/triangleAmount)),
y+(radius*sin(i*twicepi/triangleAmount))
);

};



glEnd();


x=-0.3f;
y=-0.5f;
radius= 0.1f;
i;
triangleAmount=30;
//GLfloat twicepi = 2.0f*PI;
glBegin(GL_TRIANGLE_FAN);
glColor3ub(171,22,17);
for(i=0;i<=triangleAmount;i++){
glVertex2f(
x+(radius*cos(i*twicepi/triangleAmount)),
y+(radius*sin(i*twicepi/triangleAmount))
);

};
glEnd();

x=-0.6f;
y=-0.5f;
radius= 0.1f;
i;
triangleAmount=30;
//GLfloat twicepi = 2.0f*PI;
glBegin(GL_TRIANGLE_FAN);
glColor3ub(171,22,17);
for(i=0;i<=triangleAmount;i++){
glVertex2f(
x+(radius*cos(i*twicepi/triangleAmount)),
y+(radius*sin(i*twicepi/triangleAmount))
);

};
glEnd();

x=-0.85f;
y=-0.5f;
radius= 0.1f;
i;
triangleAmount=30;
// GLfloat twicepi = 2.0f*PI;
glBegin(GL_TRIANGLE_FAN);
glColor3ub(171,22,17);
for(i=0;i<=triangleAmount;i++){
glVertex2f(
x+(radius*cos(i*twicepi/triangleAmount)),
y+(radius*sin(i*twicepi/triangleAmount))
);

};
glEnd();
glPopMatrix();



glLoadIdentity();   //River
glLineWidth(50);  //Upper line
glBegin(GL_LINES);
glColor3ub(5, 184, 250);
glVertex2f(-1.0f,0.0f);
glVertex2f(1.0f,0.0f);
glEnd();

glLineWidth(50);
glBegin(GL_LINES);  //Lower line
glColor3ub(5, 184, 250);
glVertex2f(-1.0f,-0.2f);
glVertex2f(1.0f,-0.2f);
glEnd();

glTranslatef(-1.0f,0.0f,0.0f);
glPushMatrix();
glTranslatef(position1,0.0f, 0.0f);
glBegin(GL_QUADS);     //Boat
glColor3ub(1, 16, 2); //Black
glVertex2f(0.8f,-0.1f);
glVertex2f(0.9f,0.0f);
glVertex2f(0.5f,0.0f);
glVertex2f(0.6f,-0.1f);
glEnd();

glBegin(GL_QUADS);  //Red
glColor3ub(249, 51, 3);
glVertex2f(0.8f,0.0f);
glVertex2f(0.6f,0.0f);
glVertex2f(0.65f,0.075f);
glVertex2f(0.75f,0.075f);
glEnd();
glPopMatrix();

glLoadIdentity();
glBegin(GL_TRIANGLES);  //Green mountain
glColor3ub(40, 142, 23);
glVertex2f(1.0f,0.1f);
glVertex2f(0.6f,0.1f);
glVertex2f(0.8f,0.6f);
glEnd();

glBegin(GL_TRIANGLES);
glColor3ub(40, 142, 23);
glVertex2f(0.2f,0.1f);
glVertex2f(0.6f,0.1f);
glVertex2f(0.4f,0.6f);
glEnd();

glBegin(GL_TRIANGLES);
glColor3ub(40, 142, 23);
glVertex2f(0.2f,0.1f);
glVertex2f(-0.2f,0.1f);
glVertex2f(0.0f,0.6f);
glEnd();

glBegin(GL_TRIANGLES);
glColor3ub(40, 142, 23);
glVertex2f(-0.6f,0.1f);
glVertex2f(-0.2f,0.1f);
glVertex2f(-0.4f,0.6f);
glEnd();

glBegin(GL_TRIANGLES);
glColor3ub(40, 142, 23);
glVertex2f(-0.6f,0.1f);
glVertex2f(-1.0f,0.1f);
glVertex2f(-0.8f,0.6f);
glEnd();

glBegin(GL_TRIANGLES);
glColor3ub(40, 142, 23);
glVertex2f(-0.4f,0.1f);
glVertex2f(-0.8f,0.1f);
glVertex2f(-0.6f,0.6f);
glEnd();

glBegin(GL_TRIANGLES);
glColor3ub(40, 142, 23);
glVertex2f(-0.4f,0.1f);
glVertex2f(-0.0f,0.1f);
glVertex2f(-0.2f,0.6f);
glEnd();

glBegin(GL_TRIANGLES);
glColor3ub(40, 142, 23);
glVertex2f(-0.0f,0.1f);
glVertex2f(0.4f,0.1f);
glVertex2f(0.2f,0.6f);
glEnd();


glLineWidth(1);
glPushMatrix();
glTranslatef(0.0f,-position,0.0f);
glBegin(GL_LINES);
glColor3ub(255, 255, 255);


glVertex2f(-0.9,1);
glVertex2f(-0.9,0.95);

glVertex2f(-0.8,1);
glVertex2f(-0.8,0.95);

glVertex2f(-0.7,1);
glVertex2f(-0.7,0.95);

glVertex2f(-0.6,1);
glVertex2f(-0.6,0.95);

glVertex2f(-0.5,1);
glVertex2f(-0.5,0.95);

glVertex2f(-0.4,1);
glVertex2f(-0.4,0.95);

glVertex2f(-0.3,1);
glVertex2f(-0.3,0.95);

glVertex2f(-0.2,1);
glVertex2f(-0.2,0.95);

glVertex2f(-0.1,1);
glVertex2f(-0.1,0.95);

glVertex2f(0.0,1);
glVertex2f(0.0,0.95);

glVertex2f(0.1,1);
glVertex2f(0.1,0.95);

glVertex2f(0.2,1);
glVertex2f(0.2,0.95);

glVertex2f(0.3,1);
glVertex2f(0.3,0.95);

glVertex2f(0.4,1);
glVertex2f(0.4,0.95);

glVertex2f(0.5,1);
glVertex2f(0.5,0.95);

glVertex2f(0.6,1);
glVertex2f(0.6,0.95);

glVertex2f(0.7,1);
glVertex2f(0.7,0.95);

glVertex2f(0.8,1);
glVertex2f(0.8,0.95);

glVertex2f(0.9,1);
glVertex2f(0.9,0.95);

glVertex2f(-0.9,.8);
glVertex2f(-0.9,0.75);

glVertex2f(-0.8,.8);
glVertex2f(-0.8,0.75);

glVertex2f(-0.7,.8);
glVertex2f(-0.7,0.75);

glVertex2f(-0.6,.8);
glVertex2f(-0.6,0.75);

glVertex2f(-0.5,.8);
glVertex2f(-0.5,0.75);

glVertex2f(-0.4,.8);
glVertex2f(-0.4,0.75);

glVertex2f(-0.3,.8);
glVertex2f(-0.3,0.75);

glVertex2f(-0.2,.8);
glVertex2f(-0.2,0.75);

glVertex2f(-0.1,.8);
glVertex2f(-0.1,0.75);

glVertex2f(0.0,.8);
glVertex2f(0.0,0.75);

glVertex2f(0.1,.8);
glVertex2f(0.1,0.75);

glVertex2f(0.2,.8);
glVertex2f(0.2,0.75);

glVertex2f(0.3,.8);
glVertex2f(0.3,0.75);

glVertex2f(0.4,.8);
glVertex2f(0.4,0.75);

glVertex2f(0.5,.8);
glVertex2f(0.5,0.75);

glVertex2f(0.6,.8);
glVertex2f(0.6,0.75);

glVertex2f(0.7,.8);
glVertex2f(0.7,0.75);

glVertex2f(0.8,.8);
glVertex2f(0.8,0.75);

glVertex2f(0.9,.8);
glVertex2f(0.9,0.75);

glVertex2f(-0.9,.6);
glVertex2f(-0.9,0.55);

glVertex2f(-0.8,.6);
glVertex2f(-0.8,0.55);

glVertex2f(-0.7,.6);
glVertex2f(-0.7,0.55);

glVertex2f(-0.6,.6);
glVertex2f(-0.6,0.55);

glVertex2f(-0.5,.6);
glVertex2f(-0.5,0.55);

glVertex2f(-0.4,.6);
glVertex2f(-0.4,0.55);

glVertex2f(-0.3,.6);
glVertex2f(-0.3,0.55);

glVertex2f(-0.2,.6);
glVertex2f(-0.2,0.55);

glVertex2f(-0.1,.6);
glVertex2f(-0.1,0.55);

glVertex2f(0.0,.6);
glVertex2f(0.0,0.55);

glVertex2f(0.1,.6);
glVertex2f(0.1,0.55);

glVertex2f(0.2,.6);
glVertex2f(0.2,0.55);

glVertex2f(0.3,.6);
glVertex2f(0.3,0.55);

glVertex2f(0.4,.6);
glVertex2f(0.4,0.55);

glVertex2f(0.5,.6);
glVertex2f(0.5,0.55);

glVertex2f(0.6,.6);
glVertex2f(0.6,0.55);

glVertex2f(0.7,.6);
glVertex2f(0.7,0.55);

glVertex2f(0.8,.6);
glVertex2f(0.8,0.55);

glVertex2f(0.9,.6);
glVertex2f(0.9,0.55);

glVertex2f(-0.9,.4);
glVertex2f(-0.9,0.35);

glVertex2f(-0.8,.4);
glVertex2f(-0.8,0.35);

glVertex2f(-0.7,.4);
glVertex2f(-0.7,0.35);

glVertex2f(-0.6,.4);
glVertex2f(-0.6,0.35);

glVertex2f(-0.5,.4);
glVertex2f(-0.5,0.35);

glVertex2f(-0.4,.4);
glVertex2f(-0.4,0.35);

glVertex2f(-0.3,.4);
glVertex2f(-0.3,0.35);

glVertex2f(-0.2,.4);
glVertex2f(-0.2,0.35);

glVertex2f(-0.1,.4);
glVertex2f(-0.1,0.35);

glVertex2f(0.0,.4);
glVertex2f(0.0,0.35);

glVertex2f(0.1,.4);
glVertex2f(0.1,0.35);

glVertex2f(0.2,.4);
glVertex2f(0.2,0.35);

glVertex2f(0.3,.4);
glVertex2f(0.3,0.35);

glVertex2f(0.4,.4);
glVertex2f(0.4,0.35);

glVertex2f(0.5,.4);
glVertex2f(0.5,0.35);

glVertex2f(0.6,.4);
glVertex2f(0.6,0.35);

glVertex2f(0.7,.4);
glVertex2f(0.7,0.35);

glVertex2f(0.8,.4);
glVertex2f(0.8,0.35);

glVertex2f(0.9,.4);
glVertex2f(0.9,0.35);

glVertex2f(-0.9,.2);
glVertex2f(-0.9,0.15);

glVertex2f(-0.8,.2);
glVertex2f(-0.8,0.15);

glVertex2f(-0.7,.2);
glVertex2f(-0.7,0.15);

glVertex2f(-0.6,.2);
glVertex2f(-0.6,0.15);

glVertex2f(-0.5,.2);
glVertex2f(-0.5,0.15);

glVertex2f(-0.4,.2);
glVertex2f(-0.4,0.15);

glVertex2f(-0.3,.2);
glVertex2f(-0.3,0.15);

glVertex2f(-0.2,.2);
glVertex2f(-0.2,0.15);

glVertex2f(-0.1,.2);
glVertex2f(-0.1,0.15);

glVertex2f(0.0,.2);
glVertex2f(0.0,0.15);

glVertex2f(0.1,.2);
glVertex2f(0.1,0.15);

glVertex2f(0.2,.2);
glVertex2f(0.2,0.15);

glVertex2f(0.3,.2);
glVertex2f(0.3,0.15);

glVertex2f(0.4,.2);
glVertex2f(0.4,0.15);

glVertex2f(0.5,.2);
glVertex2f(0.5,0.15);

glVertex2f(0.6,.2);
glVertex2f(0.6,0.15);

glVertex2f(0.7,.2);
glVertex2f(0.7,0.15);

glVertex2f(0.8,.2);
glVertex2f(0.8,0.15);

glVertex2f(0.9,.2);
glVertex2f(0.9,0.15);
glEnd();

glPopMatrix();





glFlush();
}
void display2(int val) {

glutDisplayFunc(display3);


}

/////////////////Day view///////////
void display()
{
glClearColor(0.0f,0.0f,0.0f,1.0f);
glClear(GL_COLOR_BUFFER_BIT);

glBegin(GL_QUADS);   //Background color
glColor3ub(220, 239, 241);
glVertex2f(1.0f,-1.0f);
glVertex2f(1.0f,1.0f);
glVertex2f(-1.0f,1.0f);
glVertex2f(-1.0f,-1.0f);
glEnd();

glLineWidth(4.5);   //wind mill
glBegin(GL_LINES);
glColor3ub(244, 4, 62);
glVertex2f(0.6f,0.1f);
glVertex2f(0.6f,0.6f);
glEnd();

glPushMatrix();
glTranslatef(0.6f,0.6f,0.0f);
glRotatef(i,0,0.0,0.1);

glBegin(GL_TRIANGLES);
glColor3ub(210, 159, 28);
glVertex2f(0.0f,0.0f);
glVertex2f(0.1f,0.2f);
glVertex2f(0.2f,0.15f);
glEnd();

glBegin(GL_TRIANGLES);
glColor3ub(210, 159, 28);
glVertex2f(0.0f,0.0f);
glVertex2f(-0.1f,0.2f);
glVertex2f(-0.2f,0.15f);
glEnd();

glBegin(GL_TRIANGLES);
glColor3ub(210, 159, 28);
glVertex2f(0.0f,0.0f);
glVertex2f(0.1f,-0.2f);
glVertex2f(0.0f,-0.2f);
glEnd();
glPopMatrix();
i+=0.1f;

glTranslatef(0.0f,-0.3f,0.0f); //Rail lines
glLineWidth(4.5);
glBegin(GL_LINES);
glColor3ub(84,76,72);
glVertex2f(-1.0f,-0.60f);
glVertex2f(1.0f,-0.60f);
glEnd();

glLineWidth(4.5);
glBegin(GL_LINES);
glColor3ub(84,76,72);
glVertex2f(-1.0f,-0.5f);
glVertex2f(1.0f,-0.5f);
glEnd();


glLineWidth(2);
glBegin(GL_LINES);
glColor3ub(150,70,27);
glVertex2f(-0.95f,-0.60f);
glVertex2f(-0.85f,-0.5f);
glEnd();

glLineWidth(2);
glBegin(GL_LINES);
glColor3ub(150,70,27);
glVertex2f(-0.85f,-0.60f);
glVertex2f(-0.75f,-0.5f);
glEnd();

glLineWidth(2);
glBegin(GL_LINES);
glColor3ub(150,70,27);
glVertex2f(-0.75f,-0.60f);
glVertex2f(-0.65f,-0.5f);
glEnd();

glLineWidth(2);
glBegin(GL_LINES);
glColor3ub(150,70,27);
glVertex2f(-0.65f,-0.60f);
glVertex2f(-0.55f,-0.5f);
glEnd();

glLineWidth(2);
glBegin(GL_LINES);
glColor3ub(150,70,27);
glVertex2f(-0.55f,-0.60f);
glVertex2f(-0.45f,-0.5f);
glEnd();

glLineWidth(2);
glBegin(GL_LINES);
glColor3ub(150,70,27);
glVertex2f(-0.45f,-0.60f);
glVertex2f(-0.35f,-0.5f);
glEnd();

glLineWidth(2);
glBegin(GL_LINES);
glColor3ub(150,70,27);
glVertex2f(-0.35f,-0.60f);
glVertex2f(-0.25f,-0.5f);
glEnd();

glLineWidth(2);
glBegin(GL_LINES);
glColor3ub(150,70,27);
glVertex2f(-0.25f,-0.60f);
glVertex2f(-0.15f,-0.5f);
glEnd();

glLineWidth(2);
glBegin(GL_LINES);
glColor3ub(150,70,27);
glVertex2f(-0.15f,-0.60f);
glVertex2f(-0.05f,-0.5f);
glEnd();

glLineWidth(2);
glBegin(GL_LINES);
glColor3ub(150,70,27);
glVertex2f(-0.05f,-0.60f);
glVertex2f(0.05f,-0.5f);
glEnd();

glLineWidth(2);
glBegin(GL_LINES);
glColor3ub(150,70,27);
glVertex2f(0.05f,-0.60f);
glVertex2f(0.15f,-0.5f);
glEnd();

glLineWidth(2);
glBegin(GL_LINES);
glColor3ub(150,70,27);
glVertex2f(0.15f,-0.60f);
glVertex2f(0.25f,-0.5f);
glEnd();

glLineWidth(2);
glBegin(GL_LINES);
glColor3ub(150,70,27);
glVertex2f(0.25f,-0.60f);
glVertex2f(0.35f,-0.5f);
glEnd();

glLineWidth(2);
glBegin(GL_LINES);
glColor3ub(150,70,27);
glVertex2f(0.25f,-0.60f);
glVertex2f(0.35f,-0.5f);
glEnd();

glLineWidth(2);
glBegin(GL_LINES);
glColor3ub(150,70,27);
glVertex2f(0.35f,-0.60f);
glVertex2f(0.45f,-0.5f);
glEnd();

glLineWidth(2);
glBegin(GL_LINES);
glColor3ub(150,70,27);
glVertex2f(0.45f,-0.60f);
glVertex2f(0.55f,-0.5f);
glEnd();

glLineWidth(2);
glBegin(GL_LINES);
glColor3ub(150,70,27);
glVertex2f(0.55f,-0.60f);
glVertex2f(0.65f,-0.5f);
glEnd();

glLineWidth(2);
glBegin(GL_LINES);
glColor3ub(150,70,27);
glVertex2f(0.65f,-0.60f);
glVertex2f(0.75f,-0.5f);
glEnd();

glLineWidth(2);
glBegin(GL_LINES);
glColor3ub(150,70,27);
glVertex2f(0.75f,-0.60f);
glVertex2f(0.85f,-0.5f);
glEnd();

glLineWidth(2);
glBegin(GL_LINES);
glColor3ub(150,70,27);
glVertex2f(0.85f,-0.60f);
glVertex2f(0.95f,-0.5f);
glEnd();

glLoadIdentity();     //Train
glTranslatef(-0.45f,-0.45f,0.0f);
glScalef(.75,.75,0);
glPushMatrix();
glTranslatef(position,0.0f, 0.0f);
glBegin(GL_TRIANGLES);
glColor3ub(25,38,166);
glVertex2f(0.95f,-0.5f);
glVertex2f(0.8f,-0.5f);
glVertex2f(0.8f,-0.2f);
glEnd();

glBegin(GL_QUADS);
glColor3ub(140,166,25);
glVertex2f(0.8f,-0.2f);
glVertex2f(0.5f,-0.2f);
glVertex2f(0.5f,-0.5f);
glVertex2f(0.8f,-0.5f);
glEnd();

glBegin(GL_QUADS);
glColor3ub(40,166,250);
glVertex2f(0.5f,-0.5f);
glVertex2f(0.2f,-0.5f);
glVertex2f(0.2f,-0.0f);
glVertex2f(0.5f,-0.0f);
glEnd();

glBegin(GL_QUADS);
glColor3ub(249, 239, 4);
glVertex2f(0.4f,-0.4f);
glVertex2f(0.3f,-0.4f);
glVertex2f(0.3f,-0.1f);
glVertex2f(0.4f,-0.1f);
glEnd();

glBegin(GL_QUADS);
glColor3ub(249, 239, 4);
glVertex2f(0.1f,-0.5f);
glVertex2f(-0.4f,-0.5f);
glVertex2f(-0.4f,-0.2f);
glVertex2f(0.1f,-0.2f);
glEnd();

glBegin(GL_QUADS);
glColor3ub(249, 239, 4);
glVertex2f(-0.5f,-0.5f);
glVertex2f(-0.95f,-0.5f);
glVertex2f(-0.95f,-0.2f);
glVertex2f(-0.5f,-0.2f);
glEnd();

glLineWidth(7.5);
glBegin(GL_LINES);
glColor3ub(245,246,250);
glVertex2f(-0.5f,-0.45f);
glVertex2f(-0.4f,-0.45f);
glEnd();
glLineWidth(7.5);
glBegin(GL_LINES);
glColor3ub(240,240,240);
glVertex2f(0.2f,-0.45f);
glVertex2f(0.1f,-0.45f);
glEnd();

GLfloat    x=0.75f;     //Train wheel
GLfloat y=-0.5f;
GLfloat radius= 0.1f;
int   i;
int triangleAmount=30;
GLfloat twicepi = 2.0f*PI;
glBegin(GL_TRIANGLE_FAN);
glColor3ub(171,22,17);
for(i=0;i<=triangleAmount;i++){
glVertex2f(
x+(radius*cos(i*twicepi/triangleAmount)),
y+(radius*sin(i*twicepi/triangleAmount))
);

};
glEnd();

x=0.35f;
y=-0.5f;
radius= 0.1f;
i;
triangleAmount=30;
//GLfloat twicepi = 2.0f*PI;
glBegin(GL_TRIANGLE_FAN);
glColor3ub(171,22,17);
for(i=0;i<=triangleAmount;i++){
glVertex2f(
x+(radius*cos(i*twicepi/triangleAmount)),
y+(radius*sin(i*twicepi/triangleAmount))
);

};
glEnd();


x=-0.0f;
y=-0.5f;
radius= 0.1f;
i;
triangleAmount=30;
//GLfloat twicepi = 2.0f*PI;
glBegin(GL_TRIANGLE_FAN);
glColor3ub(171,22,17);
for(i=0;i<=triangleAmount;i++){
glVertex2f(
x+(radius*cos(i*twicepi/triangleAmount)),
y+(radius*sin(i*twicepi/triangleAmount))
);

};



glEnd();


x=-0.3f;
y=-0.5f;
radius= 0.1f;
i;
triangleAmount=30;
//GLfloat twicepi = 2.0f*PI;
glBegin(GL_TRIANGLE_FAN);
glColor3ub(171,22,17);
for(i=0;i<=triangleAmount;i++){
glVertex2f(
x+(radius*cos(i*twicepi/triangleAmount)),
y+(radius*sin(i*twicepi/triangleAmount))
);

};
glEnd();

x=-0.6f;
y=-0.5f;
radius= 0.1f;
i;
triangleAmount=30;
//GLfloat twicepi = 2.0f*PI;
glBegin(GL_TRIANGLE_FAN);
glColor3ub(171,22,17);
for(i=0;i<=triangleAmount;i++){
glVertex2f(
x+(radius*cos(i*twicepi/triangleAmount)),
y+(radius*sin(i*twicepi/triangleAmount))
);

};
glEnd();

x=-0.85f;
y=-0.5f;
radius= 0.1f;
i;
triangleAmount=30;
// GLfloat twicepi = 2.0f*PI;
glBegin(GL_TRIANGLE_FAN);
glColor3ub(171,22,17);
for(i=0;i<=triangleAmount;i++){
glVertex2f(
x+(radius*cos(i*twicepi/triangleAmount)),
y+(radius*sin(i*twicepi/triangleAmount))
);

};
glEnd();
glPopMatrix();



glLoadIdentity();   //River
glLineWidth(50);  //Upper line
glBegin(GL_LINES);
glColor3ub(5, 184, 250);
glVertex2f(-1.0f,0.0f);
glVertex2f(1.0f,0.0f);
glEnd();

glLineWidth(50);
glBegin(GL_LINES);  //Lower line
glColor3ub(5, 184, 250);
glVertex2f(-1.0f,-0.2f);
glVertex2f(1.0f,-0.2f);
glEnd();

glTranslatef(-1.0f,0.0f,0.0f);
glPushMatrix();
glTranslatef(position1,0.0f, 0.0f);
glBegin(GL_QUADS);     //Boat
glColor3ub(1, 16, 2); //Black
glVertex2f(0.8f,-0.1f);
glVertex2f(0.9f,0.0f);
glVertex2f(0.5f,0.0f);
glVertex2f(0.6f,-0.1f);
glEnd();

glBegin(GL_QUADS);  //Red
glColor3ub(249, 51, 3);
glVertex2f(0.8f,0.0f);
glVertex2f(0.6f,0.0f);
glVertex2f(0.65f,0.075f);
glVertex2f(0.75f,0.075f);
glEnd();
glPopMatrix();

glLoadIdentity();
glBegin(GL_TRIANGLES);  //Green mountain
glColor3ub(40, 142, 23);
glVertex2f(1.0f,0.1f);
glVertex2f(0.6f,0.1f);
glVertex2f(0.8f,0.6f);
glEnd();

glBegin(GL_TRIANGLES);
glColor3ub(40, 142, 23);
glVertex2f(0.2f,0.1f);
glVertex2f(0.6f,0.1f);
glVertex2f(0.4f,0.6f);
glEnd();

glBegin(GL_TRIANGLES);
glColor3ub(40, 142, 23);
glVertex2f(0.2f,0.1f);
glVertex2f(-0.2f,0.1f);
glVertex2f(0.0f,0.6f);
glEnd();

glBegin(GL_TRIANGLES);
glColor3ub(40, 142, 23);
glVertex2f(-0.6f,0.1f);
glVertex2f(-0.2f,0.1f);
glVertex2f(-0.4f,0.6f);
glEnd();

glBegin(GL_TRIANGLES);
glColor3ub(40, 142, 23);
glVertex2f(-0.6f,0.1f);
glVertex2f(-1.0f,0.1f);
glVertex2f(-0.8f,0.6f);
glEnd();

glBegin(GL_TRIANGLES);
glColor3ub(40, 142, 23);
glVertex2f(-0.4f,0.1f);
glVertex2f(-0.8f,0.1f);
glVertex2f(-0.6f,0.6f);
glEnd();

glBegin(GL_TRIANGLES);
glColor3ub(40, 142, 23);
glVertex2f(-0.4f,0.1f);
glVertex2f(-0.0f,0.1f);
glVertex2f(-0.2f,0.6f);
glEnd();

glBegin(GL_TRIANGLES);
glColor3ub(40, 142, 23);
glVertex2f(-0.0f,0.1f);
glVertex2f(0.4f,0.1f);
glVertex2f(0.2f,0.6f);
glEnd();
glutTimerFunc(1500,display2,0);

glFlush();
}

void dis()
{
glutDisplayFunc(display);
}

int main(int argc,char** argv)
{
glutInit(&argc,argv);
glutCreateWindow("train Station");
glutInitWindowSize(450,450);
glutInitWindowPosition(50, 50);
glutDisplayFunc(dis);
init();
glutTimerFunc(100, update, 0);
glutTimerFunc(100, update1, 0);
glutIdleFunc(Idle);
glutSpecialFunc(SpecialInput);

glutMainLoop();
return 0;
}







Step by Step Solution

3.51 Rating (154 Votes )

There are 3 Steps involved in it

Step: 1

Cpmputer Graphics Add Day D nightN code include include include include include include include defi... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

University Physics with Modern Physics

Authors: Hugh D. Young, Roger A. Freedman, Lewis Ford

12th Edition

978-0321501479, 9780805321876, 321501470, 978-0321501219

More Books

Students also viewed these Computer Engineering questions

Question

What costs should be covered by the selling price of a new product?

Answered: 1 week ago

Question

how can i seperate the time given in assembly 8 0 8 6

Answered: 1 week ago

Question

7. What is the relationship between birth order and homosexuality?

Answered: 1 week ago

Question

5. What does the enzyme 5a-reductase 2 do?

Answered: 1 week ago