Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- ArrayList<Thing> things;
- float particlesPerFirework = 30;
- //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;
- Thing(float x, float y)
- {
- this.x = x;
- this.y = y;
- size = 4;
- hue = random(100);//random hue
- vx = random(10) - 5;
- vy = random(10) - 5;
- }
- //Draws the "thing"
- void drawMe()
- {
- fill(hue, 100, 100);
- ellipse(x, y, size, size);
- //System.out.println("Drawing at "+x+" "+" "+y);
- }
- void fall()
- {
- vy += .1;
- }
- 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.fall();
- //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