[go: up one dir, main page]

0% found this document useful (0 votes)
6 views8 pages

Assignment 01 Haider Ali 2679

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 8

National University of Modern Languages

Assignment 01
Title
Computer Graphics

Haider Ali (2679) <-(Mine)


Group Member 1: Basit Hussian (2670)
Group Member 2: Fahad Rafi (2671)
BSCS 7th B Morning
Submitted to : Madam Sabina

Paper Due Date

October 24, 2024


Assignment 1
Create a park with new objects: a bench, a lamppost, a bird, a river, and a mountain. Each object
will be drawn using basic shapes (lines, polygons, circles), and we'll apply transformations to
modify the appearance of some objects.

Scene Description:

 Bench: A simple rectangle for the seat and vertical lines for the legs.
 Lamppost: A tall vertical rectangle for the post with a circle for the lamp.
 Bird: A simple V-shaped bird in the sky.
 River: A long curving line for the river.
 Mountain: Triangular mountains in the background.

Code OPENGL

#include <windows.h>
#include <GL/gl.h>
#include <GL/glut.h>

void drawLamppost();
void drawBirds();
void drawBench();
void drawHouses();
void drawBoats();
void drawRiver();
void drawSun();
void drawTrees();
void drawMountain();
void ground();

void mydisplay() {
glClear(GL_COLOR_BUFFER_BIT);

ground();
drawRiver();
drawMountain();
drawHouses();
drawTrees();
drawBoats();
drawSun();
drawBench();
drawLamppost();
drawBirds();

glFlush();
}

void drawBench() {
// Bench seat (rectangle)
glColor3f(0.6, 0.3, 0.0);
glBegin(GL_POLYGON);
glVertex2i(170, 55);
glVertex2i(200, 55);
glVertex2i(200, 65);
glVertex2i(170, 65);
glEnd();

// Bench legs (lines)


glLineWidth(2.0);
glColor3f(0.0, 0.0, 0.0);
glBegin(GL_LINES);
// Left leg
glVertex2i(175, 55);
glVertex2i(175, 50);
// Right leg
glVertex2i(195, 55);
glVertex2i(195, 50);
glEnd();
}

void drawLamppost() {
// Post (rectangle)
glColor3f(0.4, 0.4, 0.4);
glBegin(GL_POLYGON);
glVertex2i(175, 70); // Base of the post
glVertex2i(178, 70);
glVertex2i(178, 85); // Top of the post
glVertex2i(175, 85);
glEnd();

// Lamp light (square)


glColor3f(1.0, 0.5, 0.0); // Orange color for the light
glBegin(GL_POLYGON);
glVertex2i(173, 85); // Bottom left of the light
glVertex2i(181, 85); // Bottom right of the light
glVertex2i(181, 91); // Top right of the light
glVertex2i(173, 91); // Top left of the light
glEnd();
}

void drawBirds() {
glColor3f(0.0, 0.0, 0.0);
glLineWidth(1.0);

// First bird
glBegin(GL_LINES);
glVertex2i(30, 150);
glVertex2i(35, 145);
glVertex2i(35, 145);
glVertex2i(40, 150);
glEnd();

// Second bird
glBegin(GL_LINES);
glVertex2i(45, 160);
glVertex2i(50, 155);
glVertex2i(50, 155);
glVertex2i(55, 160);
glEnd();

// Third bird
glBegin(GL_LINES);
glVertex2i(60, 145);
glVertex2i(65, 140);
glVertex2i(65, 140);
glVertex2i(70, 145);
glEnd();
glFlush();
}

void drawHouses() {
// First house (blue roof, yellow door, purple walls)
glColor3f(0.0, 0.0, 1.0); // Blue roof
glBegin(GL_POLYGON);
glVertex2i(50, 70);
glVertex2i(75, 100);
glVertex2i(100, 70);
glEnd();

glColor3f(0.6, 0.0, 0.6); // Purple walls


glBegin(GL_POLYGON);
glVertex2i(55, 40);
glVertex2i(55, 70);
glVertex2i(95, 70);
glVertex2i(95, 40);
glEnd();

glColor3f(1.0, 1.0, 0.0); // Yellow door


glBegin(GL_POLYGON);
glVertex2i(70, 40);
glVertex2i(70, 55);
glVertex2i(80, 55);
glVertex2i(80, 40);
glEnd();

// Second house (orange roof, yellow door, purple walls)


glColor3f(1.0, 0.5, 0.0); // Orange roof
glBegin(GL_POLYGON);
glVertex2i(110, 70);
glVertex2i(135, 100);
glVertex2i(160, 70);
glEnd();

glColor3f(0.6, 0.0, 0.6); // Purple walls


glBegin(GL_POLYGON);
glVertex2i(115, 40);
glVertex2i(115, 70);
glVertex2i(155, 70);
glVertex2i(155, 40);
glEnd();

glColor3f(1.0, 1.0, 0.0); // Yellow door


glBegin(GL_POLYGON);
glVertex2i(130, 40);
glVertex2i(130, 55);
glVertex2i(140, 55);
glVertex2i(140, 40);
glEnd();
}

void drawBoats() {
// First boat (black base, red top)
glColor3f(0.0, 0.0, 0.0); // Black base
glBegin(GL_POLYGON);
glVertex2i(50, 20);
glVertex2i(70, 20);
glVertex2i(65, 15);
glVertex2i(55, 15);
glEnd();

glColor3f(1.0, 0.0, 0.0); // Red top


glBegin(GL_POLYGON);
glVertex2i(55, 20);
glVertex2i(55, 25);
glVertex2i(65, 25);
glVertex2i(65, 20);
glEnd();

// Second boat (black base, red top)


glColor3f(0.0, 0.0, 0.0); // Black base
glBegin(GL_POLYGON);
glVertex2i(90, 20);
glVertex2i(110, 20);
glVertex2i(105, 15);
glVertex2i(95, 15);
glEnd();

glColor3f(1.0, 0.0, 0.0); // Red top


glBegin(GL_POLYGON);
glVertex2i(95, 20);
glVertex2i(95, 25);
glVertex2i(105, 25);
glVertex2i(105, 20);
glEnd();
}

void drawRiver() {
// Blue river
glColor3f(0.0, 0.5, 1.0);
glBegin(GL_POLYGON);
glVertex2i(0, 0);
glVertex2i(200, 0);
glVertex2i(200, 30);
glVertex2i(0, 30);
glEnd();
}

void drawSun() {
// Sun as a simple ellipse shape
glColor3f(1.0, 0.5, 0.0);
glBegin(GL_POLYGON);
glVertex2i(160, 170); // Top
glVertex2i(150, 180); // Left
glVertex2i(160, 190); // Bottom
glVertex2i(170, 180); // Right
glEnd();
}

void drawTrees() {
// Tree next to the left side of the first house

glColor3f(0.0, 0.8, 0.0); // Green leaves


glBegin(GL_POLYGON);
glVertex2i(20, 50);
glVertex2i(30, 70);
glVertex2i(40, 50);
glEnd();

glColor3f(0.6, 0.2, 0.0); // Brown trunk


glBegin(GL_POLYGON);
glVertex2i(28, 40);
glVertex2i(28, 50);
glVertex2i(32, 50);
glVertex2i(32, 40);
glEnd();

void drawMountain() {
// Mountains above both houses
glColor3f(0.6, 0.3, 0.0);

// Mountain 1 (above first house)


glBegin(GL_POLYGON);
glVertex2i(40, 100);
glVertex2i(75, 140);
glVertex2i(110, 100);
glEnd();

// Mountain 2 (above second house)


glBegin(GL_POLYGON);
glVertex2i(120, 100);
glVertex2i(155, 140);
glVertex2i(190, 100);
glEnd();
}

void ground() {
// Green ground
glColor3f(0.8078, 0.9490, 0.6824);
glBegin(GL_POLYGON);
glVertex2i(0, 30);
glVertex2i(200, 30);
glVertex2i(200, 100);
glVertex2i(0, 100);
glEnd();
}
void MyInit() {
glClearColor(0.5, 0.8, 1.0, 1.0); // Light blue background for sky
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 200.0, 0.0, 200.0);
}

int main(int argc, char* argv[]) {


glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500, 400);
glutInitWindowPosition(100, 150);
glutCreateWindow("Village Scene");
glutDisplayFunc(mydisplay);
MyInit();
glutMainLoop();
return 0;
}
OUTPUT

You might also like