0% found this document useful (0 votes)
52 views9 pages

CG Mini Project Sample Report 1 PDF

This document outlines a mini project that involves creating an animated weather simulation using C graphics, showcasing three weather conditions: sunny, rainy, and snowy. The program allows users to switch between these conditions interactively, employing various algorithms for animation and user input handling. The project serves as an educational tool for understanding basic graphical programming concepts in C/C++.

Uploaded by

vaishupc17
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)
52 views9 pages

CG Mini Project Sample Report 1 PDF

This document outlines a mini project that involves creating an animated weather simulation using C graphics, showcasing three weather conditions: sunny, rainy, and snowy. The program allows users to switch between these conditions interactively, employing various algorithms for animation and user input handling. The project serves as an educational tool for understanding basic graphical programming concepts in C/C++.

Uploaded by

vaishupc17
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

Computer Graphics Mini

Project Design of Animated Weather System

Submitted in partial fulfillment of the requirements of the degree

SECOND YEAR COMPUTER ENGINEERING

By

Mayur Narkhede Comp B 06


Aastha Oswal Comp B 12
Vaishnavi Patil Comp B 14
Harshani Patil Comp B 20

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
Abstract
This C program presents an interactive weather simulation using basic graphics. It employs the
graphics library in C to create an animated depiction of three different weather conditions:
sunny, rainy, and snowy. The simulation starts by displaying a default sky, and the user can
switch between the weather conditions using keyboard input (pressing '1' for a sunny day, '2' for
a rainy day, '3' for a snowy night). Each weather condition is animated uniquely. In the sunny
mode, a pulsating sun is drawn at a fixed position, with its size gradually increasing and
decreasing to simulate the sun's natural expansion and contraction. In the rainy mode, the
program randomly generates and animates raindrops falling across the screen. For the snowy
mode, the program displays snowflakes falling at random positions.

The sun animation is achieved by altering the circle size in each frame, while the rain and snow
effects are rendered by drawing random lines and small circles, respectively, across the screen. A
key feature of this program is the dynamic and real-time control users have to switch between
different weather conditions, making it interactive and visually engaging. The program runs in
an infinite loop, continually updating the weather display based on user input, until the user
presses 'Q' to quit the simulation. A custom delay() function controls the frame rate of the
animation, ensuring smooth transitions and movement. This simulation serves as an educational
example of using basic graphics programming for creating interactive visual effects in C.

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.

Animated Weather System:


In this micro-project we have done animation of Weather System which is title of our
report. Our micro-project Includes Following five Algorithms:-

1)Pulsating Sun Algorithm (Size Animation)


2) Random Rain Algorithm
4)Snow Placement Algorithm 3)
Screen Clearing Algorithm
4) Input Handling Algorithm
5) Delay Algorithm
1)Pulsating Sun Algorithm (Size Animation)
The sun pulsates (grows and shrinks in size) in a simple algorithm that uses conditional logic to
alternate the sun’s radius between a minimum and maximum value.

Steps:
1. The size of the sun (sunSize) starts at a base value (50 in this case).
2. The size is incremented or decremented in each frame, depending on the direction (1 for
increasing, -1 for decreasing).
3. When the size reaches a threshold (either too big or too small), the direction reverses
(direction *= -1), causing the sun to either shrink or grow.

2) Random Rain Algorithm


Raindrops are drawn randomly on the screen using a simple *random number generation
algorithm*. The rand() function generates random x and y coordinates for each raindrop within
the dimensions of the screen.
Steps:
1. A loop runs 100 times, each time generating random x and y positions.
2. A vertical line is drawn at the random coordinates, representing a raindrop.

3) Snowflake Algorithm
The snowflake algorithm works similarly to the raindrop algorithm, with the difference being
that instead of lines, snowflakes are drawn as small circles.
Steps:
1. A loop runs 100 times, generating random x and y positions for each snowflake.
2. Small circles are drawn at each random position.

4) Screen Clearing Algorithm


Before each new frame is drawn, the screen needs to be cleared and reset to a base color. The
clearScreen() function is responsible for filling the entire screen with a solid color using a
rectangle (the bar() function).

Steps:
1. The function sets the fill style to a solid color (e.g., black, light blue, etc.).
2. It then fills the screen using the bar() function, which draws a filled rectangle over the entire
screen.

5) Delay Algorithm
The delay for the animation is implemented using a custom delay() function, which creates a
pause in the program’s execution. This function is based on the system clock and creates a delay
for a specified number of milliseconds.

Steps:
1. The clock() function returns the current processor time.
2. The program waits in a loop until the required time has passed.
3. The loop continually checks if the current time has exceeded the delay time.

6) User Input Handling Algorithm


The program uses keyboard input to let the user change between different weather modes (sun,
rain, snow) or quit the program. The kbhit() and getch() functions are used to detect key presses.
Steps:

1. The program continuously checks if a key has been pressed using kbhit().

2. If a key is pressed, getch() reads the key.

3. The key is then compared to predefined options (1, 2, 3 for weather modes, q or Q to quit).

Project Goal:
The goal of this project is to create an interactive weather simulation using C++ graphics. It allows
users to visualize different weather conditions—sunny, rainy, and snowy—by simulating an
animated sun, raindrops, and snowflakes. The user can toggle between these weather types via
keyboard input, with smooth transitions and real-time animations.

Scope:
It is developed in Turbo c++. It has been implemented on Windows platform. We have
used different graphics algorithms which are implemented in c++ like bresenham’s line drawing
algorithm, bresenham’s circle drawing algorithm and flood fill algorithm are are used for various
graphical shapes and to fill color in that graphical shapes.
Source Code:

#include <graphics.h> #include


<conio.h>
#include <stdlib.h>
#include <time.h>
#include <dos.h> // For delay() function

// Prototype for the delay function


void delay(unsigned int ms);

// Function to draw the animated sun (pulsating effect)


void drawSun(int size) { setcolor(YELLOW); // Set
sun color to YELLOW circle(100, 100, size); // Draw
sun with dynamic size setfillstyle(SOLID_FILL,
YELLOW); // Fill sun floodfill(100, 100,
YELLOW); // Fill inside the circle }

// Function to draw raindrops void


drawRain() {
for (int i = 0; i < 100; i++) {
int x = rand() % getmaxx(); // Random x-coordinate
int y = rand() % getmaxy(); // Random y-coordinate
setcolor(LIGHTBLUE);
line(x, y, x, y + 15); // Draw larger raindrop
}
}

// Function to draw snowflakes void


drawSnow() {
for (int i = 0; i < 100; i++) { int x = rand() %
getmaxx(); // Random x-coordinate int y = rand() %
getmaxy(); // Random y-coordinate
setcolor(WHITE);
circle(x, y, 2); // Draw snowflake
}
}

// Function to clear the screen and set background color


void clearScreen(int color) {
setfillstyle(SOLID_FILL, color); bar(0, 0,
getmaxx(), getmaxy());
}

int main() { int gd =


DETECT, gm;
initgraph(&gd, &gm, "C:\\Turboc3\\BGI");

int sunSize = 50; // Initial size of the sun int


direction = 1; // Direction to grow or shrink the sun
char choice = '0'; // Weather choice

srand(time(0)); // Seed for random number generation

while (1) {
// Clear the screen based on the weather type
if (choice == '1') {
clearScreen(BLACK); // BLACK for sunny day
drawSun(sunSize); // Draw animated sun
// Animate the sun by increasing and decreasing its size
sunSize += direction; if (sunSize > 60 || sunSize < 40)
{
direction *= -1; // Reverse the direction when sun reaches size limits
}
} else if (choice == '2') {
clearScreen(DARKGRAY); // Dark gray for rainy day
drawRain(); // Draw rain
} else if (choice == '3') {
clearScreen(BLACK); // Black for snowy night
drawSnow(); // Draw snow
} else {
clearScreen(LIGHTBLUE); // Default blue sky
}

// Instructions
outtextxy(10,
setcolor(WHITE);
10, "Press 1 for Sunny, 2 for Rainy, 3
for Snowy, Q to Quit");

// User input to change weather or quit


if (kbhit()) { choice = getch();
if (choice == 'Q' || choice == 'q') {
break; // Exit the loop and quit the program
}
}

delay(150); // Delay for animation effect


}

closegraph();
return 0;
}

// Definition of delay function void


delay(unsigned int ms) {
unsigned int end = clock() + ms * CLOCKS_PER_SEC / 1000;
while (clock() < end);
}

Output:
MAIN SCREEN
PRESS 1 FOR SUNNY

PRESS 2 FOR RAINY


PRESS 3 FOR SNOWY
Conclusion:
The weather simulation program successfully implements dynamic animations using C/C++
graphics libraries. By incorporating user inputs, the project effectively simulates three different
weather conditions: a pulsating sun for sunny weather, raindrops for rainy weather, and falling
snowflakes for snowy weather. The use of randomization in positioning raindrops and
snowflakes adds a natural element to the simulation.

This project demonstrates key graphical programming concepts such as animation loops, user
interaction, and random generation. Overall, it serves as an engaging and educational tool for
understanding the basics of graphical programming in C/C++. With further development, the
program has significant potential for expansion into more complex visual simulations.

REFERENCES:

Computer Graphics: Principles and Practice" by Foley et al. (2nd edition).


1. David Blythe Introduction to Computer Graphics and the OpenGL® Pipeline IEEE
Computer Graphics and Applications Year: 2005 Page No: 14-22 .

2. Yashavant Kanetkar , Let Us C , BPB Publications ,Year: 2006 ,Page No: 215-220.

3. Brian W. Kernighan and Dennis M. Ritchie , The C Programming Language ,Prentice Hall,
Year: 1988 , Page No: 134-135

You might also like