2D Java Fireworks Explosion

Reply

Join Date: Feb 2008
Posts: 36
Reputation: CaffeineCoder is an unknown quantity at this point 
Solved Threads: 0
CaffeineCoder CaffeineCoder is offline Offline
Light Poster

2D Java Fireworks Explosion

 
0
  #1
Feb 9th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,293
Reputation: majestic0110 has a spectacular aura about majestic0110 has a spectacular aura about majestic0110 has a spectacular aura about 
Solved Threads: 67
majestic0110's Avatar
majestic0110 majestic0110 is online now Online
Nearly a Posting Virtuoso

Re: 2D Java Fireworks Explosion

 
0
  #2
Feb 10th, 2008
here you go buddy, this example has source code too.
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!
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 36
Reputation: CaffeineCoder is an unknown quantity at this point 
Solved Threads: 0
CaffeineCoder CaffeineCoder is offline Offline
Light Poster

Re: 2D Java Fireworks Explosion

 
0
  #3
Feb 10th, 2008
Originally Posted by majestic0110 View Post
here you go buddy, this example has source code too.
http://javaboutique.internet.com/fireworks/
Thanks majestic0110, I'll try that. I've been playing around with another version I found a while back, and have trouble integrating it into the rest of my app (get errors that G is null from a NullPointerException). I'll try this other one and see what I can get.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,293
Reputation: majestic0110 has a spectacular aura about majestic0110 has a spectacular aura about majestic0110 has a spectacular aura about 
Solved Threads: 67
majestic0110's Avatar
majestic0110 majestic0110 is online now Online
Nearly a Posting Virtuoso

Re: 2D Java Fireworks Explosion

 
0
  #4
Feb 10th, 2008
ok let us all know how you got on! Send us the code if you are still struggling.
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!
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 762
Reputation: Phaelax is on a distinguished road 
Solved Threads: 38
Phaelax Phaelax is offline Offline
Master Poster

Re: 2D Java Fireworks Explosion

 
0
  #5
Feb 11th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 36
Reputation: CaffeineCoder is an unknown quantity at this point 
Solved Threads: 0
CaffeineCoder CaffeineCoder is offline Offline
Light Poster

Re: 2D Java Fireworks Explosion

 
0
  #6
Feb 12th, 2008
Originally Posted by Phaelax View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 36
Reputation: CaffeineCoder is an unknown quantity at this point 
Solved Threads: 0
CaffeineCoder CaffeineCoder is offline Offline
Light Poster

Re: 2D Java Fireworks Explosion

 
0
  #7
Feb 15th, 2008
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.

  1. int gravity, a, v, T, L, x, y;
  2. double valueA, valueB, dx, dy;
  3. int t;
  4. Random r = new Random();
  5. for(t = 0; t < Explosion.length; t ++)
  6. {
  7. gravity = 20;
  8. a = r.nextInt(50);
  9. v = r.nextInt(50);
  10. valueA = v*Math.sin(a)*t;
  11. valueB = (.5)*gravity*(t*t);
  12. dx = (int)v*Math.cos(a)*t;
  13. dy = (int)valueA - valueB;
  14. x = (int)dx;
  15. y = (int)dy;
  16. Explosion = new FireworksSprite[100];
  17. //for(t = 0; t < Explosion.length; t ++)
  18. //{
  19. System.out.print("Iterating through Array" + t);
  20. Explosion[t].setSpriteH(15);
  21. Explosion[t].setSpriteW(10);
  22. Explosion[t].setLocx(x);
  23. Explosion[t].setLocy(y);
  24. Explosion[t].setActive(true);
  25. Explosion[t].setVisible(true);
  26. Explosion[t].setVel(0, v);
  27.  
  28. }
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 36
Reputation: CaffeineCoder is an unknown quantity at this point 
Solved Threads: 0
CaffeineCoder CaffeineCoder is offline Offline
Light Poster

Re: 2D Java Fireworks Explosion

 
0
  #8
Feb 16th, 2008
It WAS something simple, I left out a line initializing the array's objects. I'll leave this thread open in case I run into any further issues, and will close out once this is completed. Thanks to those who have replied, you've been great help.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC