943,725 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 6501
  • Java RSS
Feb 9th, 2008
0

2D Java Fireworks Explosion

Expand Post »
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.
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
CaffeineCoder is offline Offline
54 posts
since Feb 2008
Feb 10th, 2008
0

Re: 2D Java Fireworks Explosion

here you go buddy, this example has source code too.
http://javaboutique.internet.com/fireworks/
Reputation Points: 256
Solved Threads: 72
Nearly a Posting Virtuoso
majestic0110 is offline Offline
1,306 posts
since Oct 2007
Feb 10th, 2008
0

Re: 2D Java Fireworks Explosion

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.
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
CaffeineCoder is offline Offline
54 posts
since Feb 2008
Feb 10th, 2008
0

Re: 2D Java Fireworks Explosion

ok let us all know how you got on! Send us the code if you are still struggling.
Reputation Points: 256
Solved Threads: 72
Nearly a Posting Virtuoso
majestic0110 is offline Offline
1,306 posts
since Oct 2007
Feb 11th, 2008
0

Re: 2D Java Fireworks Explosion

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.
Reputation Points: 92
Solved Threads: 51
Practically a Posting Shark
Phaelax is offline Offline
856 posts
since Mar 2004
Feb 12th, 2008
0

Re: 2D Java Fireworks Explosion

Click to Expand / Collapse  Quote originally posted by Phaelax ...
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.
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
CaffeineCoder is offline Offline
54 posts
since Feb 2008
Feb 15th, 2008
0

Re: 2D Java Fireworks Explosion

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)
  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. }
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
CaffeineCoder is offline Offline
54 posts
since Feb 2008
Feb 16th, 2008
0

Re: 2D Java Fireworks Explosion

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.
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
CaffeineCoder is offline Offline
54 posts
since Feb 2008
Jan 19th, 2010
0
Re: 2D Java Fireworks Explosion
hey i trying to write a program that will display my girlfriends name in the different letters as each firework explodes can you put down the whole program?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cornmaster12 is offline Offline
2 posts
since Jan 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: how exeptions work/or don't
Next Thread in Java Forum Timeline: Help in Java Class





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC