Thanks to visit codestin.com
Credit goes to www.scribd.com

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

CG Report

Uploaded by

waghjayesh07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views8 pages

CG Report

Uploaded by

waghjayesh07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Computer Graphics Mini

Project Design of Man Walking In Rain

Submitted in partial fulfillment of the requirements of the degree

SECOND YEAR COMPUTER ENGINEERING

By

Vivek Sonawale – B – 76
Mohin Tadavi – B – 77
Rushikesh Tandale – B – 78
Jayesh Wagh – B – 79

Under Guidance of
Dr. Prashant Y. Itankar

Department of Computer Engineering


DATTA MEGHE COLLEGE OF ENGINEERING

AIROLI, NAVI MUMBAI - 400 708

(A.Y. 2024-25)

University of Mumbai
Introduction
Computer Graphics:
Graphics provides one of the most natural means of communicating with a computer,
since our highly developed 2D and 3D pattern recognition abilities allow us to perceive and
process pictorial data rapidly and efficiently. Interactive computer graphics is the most
important means of producing pictures since the invention of photography and television. It has
the added advantage that, with the computer, we can make pictures not only of concrete real
world objects but also of abstract, synthetic objects, such as mathematical surfaces and of data
that have no inherent geometry, such as survey results.

OpenGL:
OpenGL (Open Graphics Library) is a standard specification defining a cross language
cross platform API for writing applications that produce 2D and 3D computer graphics. The
interface consists of over 250 different function calls which can be used to draw complex 3D
scenes from simple primitives.
OpenGL serves two main purposes:

∙ To hide the complexities of interfacing with different 3D accelerators, by presenting


programmer with a single, uniform API

∙ To hide the differing capabilities of hardware platforms, by requiring that all


implementations support the full OpenGL feature set.

Man Walking In Rain Design:

This project simulates a man walking in the rain with an umbrella. The graphics have been
implemented using C with the graphics.h library, and various algorithms and techniques are used
to render the scene, including the movement of the man and falling raindrops. The project
showcases basic animation and graphical techniques.

Algorithms Used:

1. Line Drawing Algorithm (for limbs, umbrella, and raindrops)


o The man’s body parts and raindrops are drawn using simple line-drawing techniques. Although
Bresenham's Line Algorithm is typically used for precise line rendering, the simpler line
function from graphics.h is sufficient for this simulation.
o The movement of the lines representing the legs of the man is achieved by alternating
o between two different line positions, giving the illusion of walking
2. Circle Drawing Algorithm (for the head)
o The man's head is represented by a circle, and the circle function from graphics.h is utilized to
draw it. This could be implemented using Bresenham's Circle Drawing Algorithm, but in this
case, a library function is employed for simplicity.
3. Flood Fill Algorithm (for filling the umbrella)
o The umbrella is drawn using a pie slice, and the flood fill algorithm can be used to fill the
umbrella region with a solid color. However, the pieslice function used already handles the fill
internally in the library function

Project Goal:

The aim of this project is to create a simulation of a man walking in the rain while holding an
umbrella. The simulation incorporates line drawing and circle drawing techniques, alongside basic
animation and rain effects. The project demonstrates how graphical elements can be dynamically
manipulated using algorithms implemented in C.

Scope:

The project has been developed using the Turbo C++ IDE and the graphics.h library, and it
has been implemented on a Windows platform. Key graphics techniques include the use of line
drawing and circle drawing to create the figure of a man and his umbrella, as well as random
generation for simulating raindrops. This project focuses on animating the man's movement and
creating a realistic rain effect through simple C-based graphics functions.
Source Code:

#include<stdio.h>
#include<graphics.h>
#include<stdlib.h>
#include<conio.h>
#include<dos.h>
#include<time.h>

#define ScreenWidth getmaxx()


#define ScreenHeight getmaxy()
#define GroundY ScreenHeight*0.75

int ldisp = 0;
int colorChange = 0;
int lightning = 0;
int windDirection = 1;

void BackgroundTransition() {
if (colorChange % 500 == 0) {
setbkcolor((colorChange / 500) % 16);
}
colorChange++;
}

void DrawLightning() {
if (rand() % 100 == 0) {
setcolor(WHITE);
int startX = rand() % ScreenWidth;
int startY = 0;
int endX = startX + (rand() % 30 - 15);
int endY = startY + 50;

for (int i = 0; i < 4; i++) {


line(startX, startY, endX, endY);
startX = endX;
startY = endY;
endX = startX + (rand() % 30 - 15);
endY += 50;
}
delay(100);
setbkcolor(BLACK);
}
}

void DrawManAndUmbrella(int x, int ldisp) {


setcolor(WHITE);
circle(x, GroundY - 90, 10);
line(x, GroundY - 80, x, GroundY - 30);
line(x, GroundY - 70, x + 10, GroundY - 60);
line(x, GroundY - 65, x + 10, GroundY - 55);
line(x + 10, GroundY - 60, x + 20, GroundY - 70);
line(x + 10, GroundY - 55, x + 20, GroundY - 70);
line(x, GroundY - 30, x + ldisp, GroundY);
line(x, GroundY - 30, x - ldisp, GroundY);
setcolor(LIGHTBLUE);
pieslice(x + 20, GroundY - 120, 0, 180, 40);
line(x + 20, GroundY - 120, x + 20, GroundY - 70);
}

void Rain(int x) {
int i, rx, ry;
setcolor(BLUE);
for (i = 0; i < 400; i++) {
rx = rand() % ScreenWidth;
ry = rand() % ScreenHeight;
if (ry < GroundY - 4) {
if (ry < GroundY - 120 || (ry > GroundY - 120 && (rx < x - 20 || rx > x + 60))) {
line(rx, ry, rx + windDirection * 2, ry + 4);
}
}
}
}

void SplashEffect() {
int i;
for (i = 0; i < 50; i++) {
int sx = rand() % ScreenWidth;
if (sx % 10 == 0) {
setcolor(CYAN);
line(sx, GroundY, sx + 2, GroundY - 5);
line(sx + 2, GroundY - 5, sx + 4, GroundY);
}
}
}

void main() {
int gd = DETECT, gm, x = 0;
initgraph(&gd, &gm, "C:\\TurboC3\\BGI");
srand(time(0));
while (!kbhit()) {
BackgroundTransition();
setcolor(GREEN);
line(0, GroundY, ScreenWidth, GroundY);
Rain(x);
ldisp = (ldisp + 2) % 20;
DrawManAndUmbrella(x, ldisp);
DrawLightning();
if (rand() % 100 == 0) {
windDirection *= -1;
}
SplashEffect();
delay(75);
cleardevice();
x = (x + 2) % ScreenWidth;
}
getch();
}
OUTPUT:
Conclusion:

The code we have implemented for our project successfully simulates a man walking in the
rain using graphical algorithms in C. The project includes elements like dynamic rain, umbrella
movement, and frequent lightning strikes, enhancing the realism and making it visually
captivating. The project gave us the opportunity to explore and implement essential graphics
algorithms, such as line drawing for the man’s structure and umbrella, and randomness for
simulating rain and lightning effects.

This project not only improves our understanding of C programming with graphics, but
also demonstrates the beauty of simulation and how it can be used to create engaging
visualizations. The animation is both informative and entertaining, offering a blend of learning and
creativity. We are confident that our project has achieved its intended goal and will serve as an
excellent example of graphical programming in C.

REFERENCES:

1. IEEE paper for Bresenham’s Line Drawing Algorithm:


Eric Andres, "Discrete circles, rings and spheres," Computers & Graphics, Vol. 18, Centre
de Recherche en Informatique, Université Louis Pasteur, 1994.

2. IEEE paper for Bresenham’s Circle Drawing Algorithm:


S.V.Burtsev, "An efficient flood-filling algorithm," Laboratory for Computational
Methods, Vol. 17, 1993.

3. IEEE paper for random generation in visual simulations:


Abduladhem Ali, Abdulmuttalib T. Rashid, Mattia Frasca, Luigi Fortuna, "An algorithm
for multi-robot collision-free navigation based on shortest distance," Robotics and
Autonomous Systems, Vol. 75, 2016.

4. Bresenham’s Circle Drawing Algorithm:


https://www.geeksforgeeks.org/bresenhams-circle-drawing-algorithm/

5. Bresenham’s Line Drawing Algorithm:


https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm

6. Random Number Generation in C:


https://www.geeksforgeeks.org/rand-and-srand-in-ccpp/

You might also like