0% found this document useful (0 votes)
21 views

Group Project - Particle Simulation - Computer Graphics

Particle simulation

Uploaded by

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

Group Project - Particle Simulation - Computer Graphics

Particle simulation

Uploaded by

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

Group Project: Particle (Fireworks) Simulation

-----------------------------------------------------------------------------------------------
GROUP MEMBERS: 麦默德 – 1820222024, 巴戈 – 1820222043, 胡天 – 1820222022, 罗卡 - 1820222033

Why we chose “Particle Simulation in OpenGL”


We chose Particle Simulation because this project-topic helped us in understanding graphical
programming from a very basic level. It helped us on hands-on approach to learning OpenGL.
We learnt mathematical concepts such as vectors, transformations, and some physics principles
as well. We also learnt and implemented algorithm development to make particles move,
collide, detect collisions, and implement rendering techniques.
This project also helped in developing our programming skills, enhancing our proficiency in
Python, particularly in using libraries like Pygame and PyOpenGL. Moreover, this project on
particle firework simulation in OpenGL has been a very exciting one. We enjoyed making this
project from scratch. We can say that choosing this project is justified by its practical value, it
pushed us to hone our skills and work potential, and drove us towards practical applications. We
also made full use of all online resources available do make something of our own. The
availability of community support and resources makes it a fun and impactful learning
experience.

This is a Screenshot of what we achieved as our final product:


An Overview of our Project (What we created)
A particle firework simulation mimics the behavior of fireworks using a particle system. Each
firework consists of multiple particles that are initially launched in a burst, then follow individual
trajectories influenced by gravity and other forces. The simulation involves rendering these
particles in a 3D space and updating their positions, velocities, and colors over time to create a
realistic effect that we wanted to achieve.
 What is a Particle System? It is a collection of particles where each particle has
properties like position, velocity, color, and lifespan.
 What is the purpose of OpenGL? A graphics library for rendering 2D/3D vector graphics.
 What is PyCharm? Just like any other IDE, such as CodeBlocks (IDE), PyCharm is also an
integrated development environment (IDE) for Python that makes it easier to write, test,
and debug Python code.

Setting up the Environment


First thing is first, to create the project, you need to first set up the environment on your
computer so make sure you have OpenGL, PyCharm, and Visual Studio Code installed. Creating
a particle firework simulation in OpenGL and running it in PyCharm involves writing the
simulation code, and understanding how the particle system mimics fireworks. We’ll show you
how you can run our code and how everything works with all these applications that we have
mentioned.
Step 1. Install Python: Make sure Python is installed on your system.
Step 2. Install these Required Libraries:
You need to install “Pygame” and “PyOpenGL”
Open a terminal or command prompt and run the following commands:
-> pip install pygame PyOpenGL
-> pip install PyOpenGL PyOpenGL_accelerate pygame

You should see these downloads after the command input:


Step 3. Install PyCharm: Make sure PyCharm is installed
OR
Step 4. Install Visual Studio Code

Setting Up PyCharm
Open PyCharm and configure the Python interpreter:
Go to File > Settings > Project > Python Interpreter and ensure the correct Python version is
selected. Run our Code in PyCharm, or the VS file should directly take you to Visual Studio

Other Useful Tips


Ensure your graphics drivers are up to date to avoid issues with OpenGL. If you encounter any
errors, make sure you have the required permissions to access the display and other resources.

The complete Code


import pygame
from pygame.locals import *
class Particle: last_time = time.time()
from
def OpenGL.GL
__init__(self): import *
fromself.x
OpenGL.GLU import *- 0.5) * 2
= (random.random() while True:
import
self.yrandom
= (random.random() - 0.5) * 2
for event in pygame.event.get():
self.ztime
import = (random.random() - 0.5) * 2
if event.type == pygame.QUIT:
self.vx = (random.random() - 0.5) * 0.1
pygame.quit()
self.vy = (random.random() - 0.5) * 0.1
quit()
self.vz = (random.random() - 0.5) * 0.1
current_time = time.time()
self.life = random.random()
dt = current_time - last_time
def update(self, dt):
last_time = current_time
self.x += self.vx * dt
Explanation of the Code:
Imports:
Pygame, opengGL.GL, OpenGl.GLU, random, time
Pygame: Used for creating the window and handling user input.
OpenGL.GL and OpenGL.GLU: Used for rendering 3D graphics.
random and time: Used for generating random numbers and handling time intervals.

Particle Class:

Defines the properties and behavior of each particle:


__init__: Initializes particle position (x, y, z), velocity (vx, vy, vz), and life.
update(dt): Updates particle position based on velocity and decreases life over time. If life is
below zero, the particle is reinitialized.

Particle System Initialization: Creates a list of 1000 particles, that later are subject to
random movements and colors based on the code we have created to achieve the firework
effect
Main Function: The main function o the code is that it initializes Pygame. It sets up the
display with OpenGL settings and configures perspective and translation for 3D viewing. It also
enables point smoothing and sets point size.
The code enters the main loop where:
It handles events, especially for quitting.

Calculates the time interval “dt”

Clears the screen and begins drawing points, updates and draws each particle, swaps buffers
and waits for a short interval.

Project Summary
This project involves creating a particle system to simulate fireworks using OpenGL for rendering
and Pygame for window management. The key tasks include initializing particles, updating their
properties over time, and rendering them to create the firework effect. Using PyCharm or Visual
Studio Code as the IDE simplifies writing, testing, and debugging the code.

You might also like