CSE 30 -- Prog 3

Due: 11:59pm Monday, May 25, 2020 (Pacific time)
Late submissions will not be accepted/graded.

Learning Objectives:

Previously, you wrote your own Dot class as a subclass of the pygame.sprite.Sprite class. This time, you will write your own class hierarchy i.e. class that inherits from another class that you also write. We will continue to use Pygame but also add PyOpenGL for 3D effects.

Description:

You will be creating fireworks in this program! Pygame will be used for creating the display and user interaction (e.g. keyboard interactions), while PyOpenGL will be used for rendering/drawing the effects. Your fireworks will be in 3D.

On Windows, you can install PyOpenGL by: typing pip install pyopengl at the cmd prompt. On Macs, you can install PyOpenGL by: typing pip install pyopengl at the terminal.

Since we only have one week for this assignment, you are provided a starter code. Make sure you can run this code before proceeding. The code has 5 preset fireworks, 2 of them are with single colors (red, green) and the other 3 with randomly generated colors.

The requirements for this assignment are broken into several parts, which you can use to develop your code in an incremental fashion.

  1. Your first task, which is also a Quiz (due 9pm May 20), is to reorganize the starter code into multiple classes. Specifically, you want to have a Firework class that knows about fireworks. It should at least have a constructor method for creating a single firework. A firework consists of multiple particles. So, you should also have a Particle class -- which is already in the starter code. Typically, from an object-oriented design viewpoint, we would also want each particle object to know how to render itself by providing a render() method. However, this is inefficient from the point of view of OpenGL rendering -- you are calling on OpenGL to render 1 point at a time rather than a list of points. So, in this regard, you will want the Firework class to have the render() method instead. That is, each Firework object knows how to create and draw itself. To create a Firework object, it will create a bunch of Particle objects that know how to update themselves.

    After code reorganization, you should have 2 classes, and still produce the same output. Things to consider:


  2. Add gravitational effect and lifetime for each particle. At the moment, the starter code just draws the latest position of each particle for each simulation time step (see update()). Also, all the particles of that firework will suddenly disappear when the simulation time advances beyond a certain time (see main()).

    Modify the update() method to include gravitational effects. Each particle object has an initial velocity assigned to it when it is first created. Use projectile motion equation to update a particle's path. In the starter code, the y-axis is the vertical axis, the x-axis is the horizontal axis, and the z-axis is the viewing axis. So, the gravitational effects should impact the movement/velocity along the y-axis.

    Add a lifetime attribute to each particle object so that you can have fireworks that last longer, and some that last shorter. This allows the pyrotech to fire off a firework and not worry about when to "turn it off".

  3. Even with gravitational effects, there's still something missing with how our fireworks look. We need to add "comet trails" for each particle so that we can see the trajectory of each particle (rather than just its current position). This means we need to keep track of the last n positions of each particle. This can best be achieved with a queue data structure with first-in, first-out policy. You can implement your queue using the Python list collection and its associated methods e.g. see (https://www.geeksforgeeks.org/queue-in-python/

    Note that n which is directly correlated to the length of the comet trail should now be an attribute of each particle as well. This will affect how particles for a firework is displayed -- since there will be n times more particles. To further improve the appearance of the comet trail, we will use the 4th component of color specification -- alpha. By default, alpha is 1 which indicates an opaque color. You can make a particle look semi-transparent by assigning a different value of alpha. An alpha of 0 means the particle is totally transparent and therefore invisible. Since fireworks are usually done at night, and we have a black background, our comet trail should appear darker near the tail and brighter near the particle's current position. You can assign linearly varying alpha's to the particles in the tail i.e. i/n where i (in the range [n .. n-1]) is the tail particle's position relative to the particle's current position.

  4. Add fireworks with secondary explosions (i.e. more fireworks). This is another example where recursion can come in handy! However, because of the number of particles in a firework, having more than 1 level of recursion (i.e. anything more than a secondary explosion) will create too many particles for home laptops to handle. For this stage, have each of the particle in a firework also be a firework object! You will want to reduce the number of particles in a firework to begin with also.

Bonus 1: (10)

There are many types of fireworks. An interesting one is where the particle trajectory is a spiral. Here's an example where the rocket booster that sends the firework up is along a spiral path. And here's one where the particles from the explosion also follow a spiral path.

So, the challenge here is to allow the pyrotech to create a firework object that has these special effects. If you want to do other effects or types of firework, check with the instructor first.

Bonus 2: (up to 5) Create a firework display with sound and all. Amount of bonus to be decided by the reader. Max is 5 points.

You can do either or both Bonus challenges.

Resources:

Look at for inspiration and ideas on different types of fireworks.
Also look at the class url for additional links on PyOpenGL at: PyOpenGL.

Rubric:

Class attributes/methods: 20%
Gravity effect:		  20%
Lifetime:		  20%
Comet trail:		  20%
Secondary firework:	  20%

Bonus 1 only: 10% extra
Bonus 2 only: up to 5% extra
Bonus 1 and 2: up to 15% extra
                   

Who graded your assignment based on your LAST name:

Michelle Kwong          : A  - Ch
Singaravelavan Rajesh   : Co - I
Andre Navid Assadi      : J  - M
Kyle Nagao Oda          : N  - Sh
Mark Allamanno          : Si - Z

Submission:


Last modified Tuesday, 19-May-2020 09:41:20 PDT.