• API
• FAQ
• Tools
• Archive
daily pastebin goal
45%
SHARE
TWEET

# Untitled

a guest Feb 12th, 2014 137 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. //
2. ArrayList<Thing> things;
3. float particlesPerFirework = 30;
4.
5. //Add a bunch of things and "place them" somewhere
6. void populateThings()
7. {
8.   things = new ArrayList<Thing>();
9.
10.
11.   //start in the midle position
12.   float x = width/2;
13.   float y = height/2;
14.
15.   //Use mouse position for x and y.
16.   x = mouseX;
17.   y = mouseY;
18.
19.   float numberOfParticles = particlesPerFirework;
20.   float theHue = random(100);
21.   for (int i=0; i<numberOfParticles; i+=1)
22.   {
23.     //x = i*(width/numberOfParticles);
24.     //float dy = noise(i)*100;
25.     Thing aThing = new Thing(x, y);
26.     aThing.hue = theHue;
28.   }
29. }
30.
31.
32.
33. class Thing
34. {
35.   float x;
36.   float y;
37.
38.   float vx;
39.   float vy;
40.
41.   float size;
42.   float hue;
43.
44.   Thing(float x, float y)
45.   {
46.     this.x = x;
47.     this.y = y;
48.     size = 4;
49.     hue = random(100);//random hue
50.
51.     vx = random(10) - 5;
52.     vy = random(10) - 5;
53.   }
54.
55.   //Draws the "thing"
56.   void drawMe()
57.   {
58.     fill(hue, 100, 100);
59.     ellipse(x, y, size, size);
60.     //System.out.println("Drawing at "+x+" "+" "+y);
61.   }
62.
63.   void fall()
64.   {
65.     vy += .1;
66.   }
67.
68.   void moveByVel()
69.   {
70.     x += vx;
71.     y += vy;
72.   }
73.
74.   //brings to the top, but only sometimes.
75.   void maybeJump()
76.   {
77.     if (random(1000) < 1)
78.       y = 0;
79.   }
80. }
81.
82. void draw() {
83.   if (things == null) //Stop if there are no things
84.     return;
85.   for (Thing thing: things)
86.   {
87.     thing.drawMe();
88.     thing.moveByVel();
89.     thing.fall();
90.     //if(thing.y > -10+height)
91.     //  thing.maybeJump();
92.     //    p.run();
94.     //      it.remove();
95.   }
96. }
97.
98. void mouseClicked()
99. {
100.   background(0); // clear screen
101.   populateThings(); //start over
102. }
103.
104. void setup() {
105.   size(640, 360);
106.   colorMode(HSB, 100);
107.   //populateThings();
108. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top