Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- ArrayList<Thing> things;
- float particlesPerFirework = 300;
- //Add a bunch of things and "place them" somewhere
- void populateThings()
- {
- things = new ArrayList<Thing>();
- //start in the midle position
- float x = width/2;
- float y = height/2;
- //Use mouse position for x and y.
- x = mouseX;
- y = mouseY;
- float numberOfParticles = particlesPerFirework;
- float theHue = random(100);
- for (int i=0; i<numberOfParticles; i+=1)
- {
- //x = i*(width/numberOfParticles);
- //float dy = noise(i)*100;
- Thing aThing = new Thing(x, y);
- aThing.hue = theHue;
- things.add(aThing);
- }
- }
- class Thing
- {
- float x;
- float y;
- float vx;
- float vy;
- float size;
- float hue;
- float opacity;
- Thing(float x, float y)
- {
- this.x = x;
- this.y = y;
- opacity = 1;
- size = 4;
- hue = random(100);//random hue
- float angle = random(360);
- float speed = random(8);
- vx = (float) speed*cos(angle);
- vy = (float) speed*sin(angle);
- //vx = randomGaussian() * 5;
- //vy = randomGaussian() * 5;
- }
- //Draws the "thing"
- void drawMe()
- {
- fill(hue, 100, 100, 255*opacity);
- ellipse(x, y, size, size);
- //System.out.println("Drawing at "+x+" "+" "+y);
- }
- void fall()
- {
- vy += .1;
- }
- void slower(float resist)
- {
- vx = vx*(1 - resist);
- vy = vy*(1 - resist);
- opacity = opacity*(1 - resist);
- }
- void moveByVel()
- {
- x += vx;
- y += vy;
- }
- //brings to the top, but only sometimes.
- void maybeJump()
- {
- if (random(1000) < 1)
- y = 0;
- }
- }
- void draw() {
- if (things == null) //Stop if there are no things
- return;
- for (Thing thing: things)
- {
- thing.drawMe();
- thing.moveByVel();
- thing.slower(.03);
- //thing.fall();
- if (thing.y > height)
- {
- thing.vy = thing.vy*(-1);
- }
- //if(thing.y > -10+height)
- // thing.maybeJump();
- // p.run();
- // if (p.isDead()) {
- // it.remove();
- }
- }
- void mouseClicked()
- {
- background(0); // clear screen
- populateThings(); //start over
- }
- void setup() {
- size(640, 360);
- colorMode(HSB, 100);
- //populateThings();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement