Guest User

Untitled

a guest
May 25th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. public class Particle{
  2. int x;
  3. int y;
  4. int xv;
  5. int yv;
  6. int angle;
  7. int velocity = (int)(Math.random()*5);
  8. int energy;
  9. boolean dead = false;
  10. public void update(){
  11. xv = (int)(velocity * (Math.sin(angle)));
  12. yv = (int)(velocity * (Math.cos(angle)));
  13. x += xv;
  14. y += yv;
  15. energy -= 10;
  16. if(energy <= 0)
  17. dead = true;
  18.  
  19. }
  20. public void draw(Graphics2D g){
  21. Ellipse2D particle = new Ellipse2D.Float(x,y,5,5);
  22. g.setColor(Color.black);
  23. g.fill(particle);
  24. }
  25. }
  26. public class ParticleSystem{
  27. Particle[] particle = new Particle[1500];//Particle array
  28. int x;//X coordinate of particle origin
  29. int y;//Y coordinate of particle origin
  30.  
  31. ParticleSystem(int mousePx, int mousePy){
  32. x = mousePx;
  33. y = mousePy;
  34. }
  35. public void init(){
  36. for(int i = 0; i <= particle.length - 1; i++){
  37. particle[i] = new Particle();
  38. particle[i].x = x;
  39. particle[i].y = y;
  40. particle[i].energy = 255;
  41. particle[i].angle = (int)(Math.toRadians(Math.random()*i));
  42. }
  43. }
  44. public void update(){
  45. for(int i = 0; i <= particle.length - 1; i++){
  46. particle[i].update();
  47. }
  48. }
  49. public void draw(Graphics2D g){
  50. for (int i = 0; i <= particle.length - 1; i++){
  51. particle[i].draw(g);
  52. }
  53. }
  54. }
Add Comment
Please, Sign In to add comment