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

# Untitled

a guest Feb 19th, 2014 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. //
2. ArrayList<Thing> things;
3. float particlesPerFirework = 300;
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.   float opacity;
44.
45.   Thing(float x, float y)
46.   {
47.     this.x = x;
48.     this.y = y;
49.     opacity = 1;
50.     size = 4;
51.     hue = random(100);//random hue
52.
53.
54.     float angle = random(360);
55.     float speed = random(8);
56.     vx = (float) speed*cos(angle);
57.     vy = (float) speed*sin(angle);
58.     //vx = randomGaussian() * 5;
59.     //vy = randomGaussian() * 5;
60.   }
61.
62.   //Draws the "thing"
63.   void drawMe()
64.   {
65.     fill(hue, 100, 100, 255*opacity);
66.     ellipse(x, y, size, size);
67.     //System.out.println("Drawing at "+x+" "+" "+y);
68.   }
69.
70.   void fall()
71.   {
72.     vy += .1;
73.   }
74.
75.   void slower(float resist)
76.   {
77.     vx = vx*(1 - resist);
78.     vy = vy*(1 - resist);
79.     opacity = opacity*(1 - resist);
80.   }
81.   void moveByVel()
82.   {
83.     x += vx;
84.     y += vy;
85.   }
86.
87.   //brings to the top, but only sometimes.
88.   void maybeJump()
89.   {
90.     if (random(1000) < 1)
91.       y = 0;
92.   }
93. }
94.
95. void draw() {
96.   if (things == null) //Stop if there are no things
97.     return;
98.   for (Thing thing: things)
99.   {
100.     thing.drawMe();
101.     thing.moveByVel();
102.     thing.slower(.03);
103.     //thing.fall();
104.     if (thing.y > height)
105.     {
106.       thing.vy = thing.vy*(-1);
107.     }
108.     //if(thing.y > -10+height)
109.     //  thing.maybeJump();
110.     //    p.run();
112.     //      it.remove();
113.   }
114. }
115.
116. void mouseClicked()
117. {
118.   background(0); // clear screen
119.   populateThings(); //start over
120. }
121.
122. void setup() {
123.   size(640, 360);
124.   colorMode(HSB, 100);
125.   //populateThings();
126. }
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