| | |
2D Java Fireworks Explosion
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Feb 2008
Posts: 39
Reputation:
Solved Threads: 0
Hey, I'm new to the Java arena, and am trying to create an application (using JForm and JPanel) displaying a fireworks show. The problem is creating an explosion for the display. Does anyone have any recommendations for creating an explosion? I've been stuck on this for quite some time and thought I'd see if anyone had any recommendations. Thanks for any advice you can provide.
here you go buddy, this example has source code too.
http://javaboutique.internet.com/fireworks/
http://javaboutique.internet.com/fireworks/
If you have a quality, be proud of it and let it define you. Add it to the world!
If you got your answer, please mark the thread as Solved. It saves time when people are looking to contribute threads or for answers!
If you got your answer, please mark the thread as Solved. It saves time when people are looking to contribute threads or for answers!
•
•
Join Date: Feb 2008
Posts: 39
Reputation:
Solved Threads: 0
•
•
•
•
here you go buddy, this example has source code too.
http://javaboutique.internet.com/fireworks/
•
•
Join Date: Mar 2004
Posts: 765
Reputation:
Solved Threads: 38
You can use the following equation of projectile trajectory to make your explosions.
x = v*cos(a)*t
y = v*sin(a)*t - ½gt²
Keep an array of 100 or so particles that will make up the firework. Given a random velocity (v) for each particle and a random angle (a). Then just step through the time, updating their positions.
x = v*cos(a)*t
y = v*sin(a)*t - ½gt²
Keep an array of 100 or so particles that will make up the firework. Given a random velocity (v) for each particle and a random angle (a). Then just step through the time, updating their positions.
•
•
Join Date: Feb 2008
Posts: 39
Reputation:
Solved Threads: 0
•
•
•
•
You can use the following equation of projectile trajectory to make your explosions.
x = v*cos(a)*t
y = v*sin(a)*t - ½gt²
Keep an array of 100 or so particles that will make up the firework. Given a random velocity (v) for each particle and a random angle (a). Then just step through the time, updating their positions.
Thanks Phaelax, I'll try some of that. Was about to post something when I saw your reply so I'll hold off posting problem code until I play with that a bit more.
Thanks.
•
•
Join Date: Feb 2008
Posts: 39
Reputation:
Solved Threads: 0
Forgive me if this is something obvious, but I'm still getting stuck on this. Right now the elements in the array don't seem to be initializing since I get NullPointerExceptions repeatedly in the loop. Does anyone see anything I'm missing? When I placed println statements within the code I could see that the initializations didn't work.
Java Syntax (Toggle Plain Text)
int gravity, a, v, T, L, x, y; double valueA, valueB, dx, dy; int t; Random r = new Random(); for(t = 0; t < Explosion.length; t ++) { gravity = 20; a = r.nextInt(50); v = r.nextInt(50); valueA = v*Math.sin(a)*t; valueB = (.5)*gravity*(t*t); dx = (int)v*Math.cos(a)*t; dy = (int)valueA - valueB; x = (int)dx; y = (int)dy; Explosion = new FireworksSprite[100]; //for(t = 0; t < Explosion.length; t ++) //{ System.out.print("Iterating through Array" + t); Explosion[t].setSpriteH(15); Explosion[t].setSpriteW(10); Explosion[t].setLocx(x); Explosion[t].setLocy(y); Explosion[t].setActive(true); Explosion[t].setVisible(true); Explosion[t].setVel(0, v); }
![]() |
Other Threads in the Java Forum
- Previous Thread: EAN13 convertion project
- Next Thread: Converting boolean to integer
| Thread Tools | Search this Thread |
2dgraphics account android api apple applet application array arrays automation banking binary binarytree bluetooth chat chatprogramusingobjects class classes client code component data database derby design draw eclipse encryption error event exception fractal game givemetehcodez graphics gui html ide if_statement image inheritance input integer interface j2me java javadesktopapplications javaprojects jlabel jni jpanel jtextfield julia linux list loop map method methods midlethttpconnection mobile monitoring netbeans newbie nullpointerexception open-source oracle print printing problem program programming project property recursion reference ria scanner screen search server set size sms sort sourcelabs splash sql static stop string swing testautomation threads time tree ui unicode validation windows






