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

0% found this document useful (0 votes)
84 views5 pages

Fire Works Animation

GNDRFNDNJYDJMRYFYHFHFGNHFJFHMFHJFJFJYKKKKKKKKKKJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJTGJ

Uploaded by

devendratavhare6
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)
84 views5 pages

Fire Works Animation

GNDRFNDNJYDJMRYFYHFHFGNHFJFHMFHJFJFJYKKKKKKKKKKJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJTGJ

Uploaded by

devendratavhare6
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/ 5

M.E.S.

Wadia College of Engineering, Pune

Department of Computer Engineering SE 2019 Pattern

Fireworks Animation

Subject: Computer Graphics

Submitted by: [Sarthak Gawate][SE-2][Roll No.20][PRN:F23112020]

[Avej Chaugule][SE-2][Roll No.22][PRN: F23112024]

[Ayush Kharwade][SE-2][Roll No.23] [PRN: F23112025]

Under guidance of: Prof.Mahesh Shinde Sir

MINI PROJECT REPORT


Title: Fireworks Animation

Objective:

The objective of the code is to create a dynamic fireworks animation using the <graphics.h>
library, showcasing colorful explosions with randomized properties for visual variety and realism.

Prerequisites:
1. Graphics Library: Install and configure the <graphics.h> library, or use an alternative like
WinBGIm if working with modern compilers.

2. Development Environment: Use a C++ IDE such as Turbo C++, Dev-C++, or configure
Code::Blocks for graphics programming.

3. Mathematical Knowledge: Basic understanding of trigonometry to calculate spark positions


and implement circular motion.

4. Randomization: Use functions like rand() for generating random firework properties such as
color, size, and position.

5. System Compatibility: A Windows operating system or an appropriate emulator to support


legacy graphics programming.
Introduction:
The Fireworks Animation program is a mini-project in computer graphics that simulates colorful
fireworks exploding on the screen. Using the <graphics.h> library, it creates visually appealing
animations with random positions, sizes, colors, and spark patterns. This project demonstrates
the use of trigonometry, randomization, and basic graphics functions

Hardware and Software Requirements:

Hardware Requirements:
- Processor: Intel Core i3 or higher
- RAM: 4 GB or more
- Graphics Card: Any GPU supporting OpenGL 2.0 or later
- Display: 15.6” monitor or larger

Software Requirements:
- Operating System: Windows/Linux/MacOS
- Compiler: GCC/MinGW with GLUT installed
- Libraries: OpenGL Utility Toolkit (GLUT)
- IDE: Visual Studio (optional)

Design:

The Fireworks Animation project simulates a colorful firework display using the <graphics.h>
library.

1. Initialization:
o The program starts by initializing the graphics mode using initgraph(), preparing
the screen for rendering.
2. Firework Structure:
o Each firework consists of a central point and multiple sparks radiating outward.
o Properties like position, radius, number of sparks, and color are randomized to
create variety.
3. Animation:
o A continuous loop animates the fireworks, drawing them on the screen, clearing
the previous frame, and adding trail effects for realism.
4. Randomization:
o Random values are used for firework position, size, number of sparks, and color to
ensure diversity in the display.
5. Mathematics:
o Sparks are distributed in a circular pattern using trigonometric functions (cos and
sin) to calculate their positions.
6. Program Flow:
o The animation continues until a key is pressed, with fireworks being drawn,
delayed, and the screen cleared for each new frame.
This design creates a dynamic fireworks display with randomized effects, providing a visually
engaging animation.
Implementation:

1. drawFirework() Function:
This function draws a single firework explosion. It calculates the positions of sparks in a circular
pattern using trigonometry (cos and sin), and draws lines from the center to the calculated
endpoints (sparks).
2. animateFireworks() Function:
This function runs the animation loop. It continuously:
• Clears the screen (cleardevice()).
• Generates random properties (position, radius, number of sparks, color) for each firework.
• Draws the firework with the drawFirework() function.
• Creates trails by drawing multiple fireworks with increasing radius and a slight delay
between them for added realism.
• It continues until a key is pressed (kbhit()).
3. main() Function:
• Seeds the random number generator (srand(time(0))).
• Initializes the graphics mode with initgraph().
• Starts the animation with animateFireworks().
• Closes the graphics mode with closegraph() once the loop ends.

Algorithm:

1. Initialize Graphics Mode


• Start the graphics mode using initgraph() to prepare the screen for rendering.
• Initialize a random number generator using srand(time(0)) for generating random
properties of the fireworks.
2. Enter Animation Loop
• Start an infinite loop to animate fireworks continuously until a key is pressed
(kbhit()).
3. Clear the Screen
• Inside the loop, clear the screen using cleardevice() to remove the previous frame
and prepare for the new firework.
4. Generate Random Firework Properties
• Randomly generate the center position (centerX, centerY) of the firework:
o centerX: Random x-coordinate (within screen width).
o centerY: Random y-coordinate (within the upper half of the screen).
• Randomly generate the radius (size of explosion) of the firework: radius = random(50,
100).
• Randomly generate the number of sparks: numSparks = random(15, 25).
• Randomly generate the color of the firework: color = random(1, 15).
5. Draw the Firework Explosion
• Call drawFirework() function:
o This function calculates the positions of sparks around the center using
trigonometry (cos and sin), then draws lines (sparks) from the center to the
calculated points.
6. Add Trail Effects
• After the first explosion, add trail effects:
o Draw additional fireworks with increasing radius to simulate trailing sparks.
o Add a slight delay (delay(100)) between each trail to create the illusion of a
trailing effect.
7. Delay for Animation Speed
• Introduce a delay between the frames using delay(500) to control the speed of the
animation and give enough time for each firework to be visible.
8. Repeat the Process
• Repeat steps 3 to 7 for continuous firework animation.
• Continue looping until a key is pressed by the user.
9. Exit Condition
• If any key is pressed (kbhit()), exit the animation loop.
10. Close Graphics Mode
Close the graphics mode with closegraph() to release any resources and clean up.

Code for fireworks Animation:

#include <graphics.h>
#include <cstdlib> // For random number generation
#include <ctime> // For seeding the random number generator
#include <cmath> // For trigonometric functions

// Function to draw a single firework explosion


void drawFirework(int centerX, int centerY, int radius, int numSparks, int color) {
// Set the color for the firework
setcolor(color);

// Loop to draw sparks


for (int i = 0; i < numSparks; i++) {
// Calculate angle for each spark
double angle = (2 * M_PI / numSparks) * i;
// Calculate end points of each spark
int x = centerX + radius * cos(angle);
int y = centerY + radius * sin(angle);
// Draw a line from the center to the end point (spark)
line(centerX, centerY, x, y);
}
}

// Function to animate multiple fireworks


void animateFireworks() {
int windowWidth = getmaxx();
int windowHeight = getmaxy();

// Infinite loop for continuous animation


while (!kbhit()) { // Exit when a key is pressed
// Clear the screen
cleardevice();

// Generate random position and properties for a firework


int centerX = rand() % windowWidth; // Random x-coordinate
int centerY = rand() % (windowHeight / 2); // Random y-coordinate (upper half
screen)
int radius = rand() % 50 + 50; // Random radius (50 to 100)
int numSparks = rand() % 10 + 15; // Random number of sparks (15 to 25)
int color = rand() % 15 + 1; // Random color

// Draw the firework


drawFirework(centerX, centerY, radius, numSparks, color);

// Delay before clearing the screen for the next firework


delay(500);

// Draw trails for added realism


for (int i = 1; i <= 3; i++) {
drawFirework(centerX, centerY, radius + i * 10, numSparks, color);
delay(100); // Delay for trails
}
}
}

int main() {
// Seed the random number generator
srand(time(0));

// Initialize the graphics mode


int gd = DETECT, gm;
initgraph(&gd, &gm, (char*)"");

// Start the fireworks animation


animateFireworks();

// Close the graphics mode


closegraph();
return 0;
}

Conclusion:

The Fireworks Animation project successfully demonstrates creating dynamic and colorful
firework displays using C++ and the `<graphics.h>` library. By randomizing properties like
position, size, and color, the program generates varied explosions with realistic trails. This
project highlights key concepts in graphics programming, including animation, randomness, and
trigonometry, and serves as a foundation for further exploration of computer graphics.

You might also like