Advertisement
Krystman

Fireworks

Mar 5th, 2019
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.47 KB | None | 0 0
  1. class Particle {
  2.   float x;
  3.   float y;
  4.   float size;
  5.   float speedX;
  6.   float speedY;
  7.   color col;
  8.   int age;
  9. }
  10.  
  11. ArrayList<Particle> dot;
  12.  
  13. void setup() {
  14.   size(640,640);
  15.  
  16.   dot = new ArrayList<Particle>();
  17.  
  18.   for (int i=0; i<100; i++) {
  19.     /*Particle myDot = new Particle();
  20.     myDot.x = random(640);
  21.     myDot.y = random(640);
  22.     myDot.size = random(20);
  23.     myDot.speed = random(5);
  24.     myDot.col = random(255);
  25.     dot.add(myDot);*/
  26.   }
  27. }
  28.  
  29. void draw() {
  30.   println(dot.size());
  31.   background(0);
  32.   for (int i=0; i < dot.size(); i++) {
  33.     Particle myDot = dot.get(i);
  34.     noStroke();
  35.     fill(myDot.col);
  36.     ellipse(myDot.x, myDot.y, myDot.size, myDot.size);
  37.     myDot.speedY = myDot.speedY + 0.08;
  38.     myDot.x = myDot.x + myDot.speedX;
  39.     myDot.y = myDot.y + myDot.speedY;
  40.     myDot.age = myDot.age + 1;
  41.  
  42.   }
  43.   for (int i=0; i < dot.size(); i++) {
  44.     Particle myDot = dot.get(i);
  45.     if (myDot.y > 640 ||  myDot.x > 640 || myDot.y < 0 || myDot.x < 0 || myDot.age > 120) {
  46.       dot.remove(myDot);
  47.     }
  48.   }
  49. }
  50.  
  51. void mousePressed() {
  52.   for (int i=0; i<1000; i++) {
  53.     Particle myDot = new Particle();
  54.     myDot.age = 0;
  55.     myDot.x = mouseX;
  56.     myDot.y = mouseY;
  57.     myDot.size = random(20);
  58.    
  59.     float ang = random(360);
  60.     float spd = random(5);
  61.     myDot.speedX = sin(radians(ang)) * spd;
  62.     myDot.speedY = cos(radians(ang)) * spd;
  63.     colorMode(HSB);
  64.     myDot.col = color(random(30),255,255);
  65.     dot.add(myDot);
  66.   }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement