3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

LED Cube 8x8x8

Step 68PC Software: Effect 3, fireworks

PC Software: Effect 3, fireworks
This effect was quite fun to make.

To make this effect, we really had to sit down and think about how fireworks work, and which forces influence the firework particles.

We came up with a theoretical model of how fireworks work:

1) A rocket is shot up to a random position, origin_x, origin_y, origin_z.

2) The rocket explodes and throws burning particles out in random directions at random velocities.

3) The particles are slowed down by air resistance and pulled towards the ground by gravity.


With this model in mind we created a fireworks effect with a pretty convincing result. Here is how it works:

1) A random origin position is chosen. (within certain limits, x and y between 2 and 5 to keep the fireworks more or less in the center of the cube. z between 5 and 6. Fireworks exploding near the ground can be dangerous! :p)

2) The rocket, in this case a single voxel is moved up the Z axis at the x and y coordinates until it reaches origin_z.

3) An array of n particles is created. Each particle has an x, y and z coordinate as well as a velocity for each axis, dx, dy and dz.

4) We for() loop through 25 particle animation steps:

5) A slowrate is calculated, this is the air resistance. The slowrate is calculated using tan() which will return an exponentially increasing number, slowing the particles faster and faster.

6) A gravity variable is calculated. Also using tan(). The effect of gravity is also exponential. This probably isn't the mathematically correct way of calculating gravity's effect on an object, but it looks good.

7) For each particle, the x y and z coordinates are incremented by their dx, dy and dz velocities divided by the slowrate. This will make the particles move slower and slower.

8) The z coordinate is decreased by the gravity variable.

9) The particle is drawn on the cube.

10) Delay for a while, then do the next iteration of the explosion animation.


We are quite pleased with the result.
 

« Previous StepDownload PDFView All StepsNext Step »
1 comment
Jan 3, 2011. 5:57 PMancienthart says:
Instead of using the tan function, you could get an exponential function by:
(Forgive my pythonisque syntax.)

Storing a starting number between 0 and 1, say 0.9.
multiplier = 0.9
Initialise a variable, e.g. named store, to the same value:
store = multiplier
For each step, multiply the store by the multiplier:
store = store * multiplier

And return a value calculated from the store (assuming that the bottom of the cube is 0, and the top is 7):
return floor(8*store)

The reason I suggest this approach, is because ATMega's have a multiply instruction - you may be able to squeeze this approach onto the chip instead of running it through the computer. :)
Jan 5, 2011. 8:09 AMnixnope says:
The atmega chips do not have a FPU, so floating point is done in software and thus making the code-size much larger, and the floating point code will run very slow.

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
651
Followers
7
Author:chr
I like microcontrollers and LEDs :D