Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int Y_AXIS = 1;
- int X_AXIS = 2;
- ArrayList particles;
- void setup(){
- size(1000, 750, P2D);
- particles = new ArrayList();
- color skyTop = color(165, 182, 209);
- color skyBottom = color(178, 132, 71);
- color sun = color(255, 238, 0);
- color sea = color(1, 34, 86);
- color sand = color(25, 24, 0);
- setGradient(0, 0, 1000, 360, skyTop, skyBottom, 1);
- noStroke();
- fill(sun);
- ellipse(width/2, 360, 100, 100);
- filter(BLUR, 4);
- fill(sea);
- rect(0, 360, 1000, 500);
- fill(sand);
- noStroke();
- quad(0, 620, 0, 750, 1000, 750, 1000, 720);
- particles.add(new Particle(100, 100, 50, color(245), 12));
- particles.add(new Particle(916, 64, 50, color(245), 12));
- particles.add(new Particle(920, 288, 50, color(245), 12));
- particles.add(new Particle(640, 155, 50, color(245), 12));
- particles.add(new Particle(618, 84, 50, color(245), 12));
- particles.add(new Particle(482, 64, 50, color(245), 12));
- particles.add(new Particle(681, 324, 50, color(245), 12));
- particles.add(new Particle(530, 218, 50, color(245), 12));
- particles.add(new Particle(397, 157, 50, color(245), 12));
- particles.add(new Particle(191, 231, 50, color(245), 12));
- particles.add(new Particle(81, 318, 50, color(245), 12));
- particles.add(new Particle(65, 155, 50, color(245), 12));
- particles.add(new Particle(235, 81, 50, color(245), 12));
- particles.add(new Particle(382, 245, 50, color(245), 12));
- particles.add(new Particle(869, 159, 50, color(245), 12));
- for(int i = 0; i < particles.size(); i++)
- {
- Particle p = (Particle) particles.get(i);
- if(p.alive)
- {
- p.drawParticle();
- p.reproduce();
- }
- else
- particles.remove(i);
- }
- }
- void draw(){}
- void mousePressed(){
- particles.add(new Particle(mouseX, mouseY, 50, color(245), 12));
- println(mouseX + "x" + mouseY);
- }
- void setGradient(int x, int y, float w, float h, color c1, color c2, int axis ) {
- noFill();
- if (axis == Y_AXIS) { // Top to bottom gradient
- for (int i = y; i <= y+h; i++) {
- float inter = map(i, y, y+h, 0, 1);
- color c = lerpColor(c1, c2, inter);
- stroke(c);
- line(x, i, x+w, i);
- }
- }
- else if (axis == X_AXIS) { // Left to right gradient
- for (int i = x; i <= x+w; i++) {
- float inter = map(i, x, x+w, 0, 1);
- color c = lerpColor(c1, c2, inter);
- stroke(c);
- line(i, y, i, y+h);
- }
- }
- }
- class Particle
- {
- PVector position;
- float oppacity;
- float w;
- color clr;
- boolean alive;
- protected Particle(float x, float y, float wth, color c, float o)
- {
- position = new PVector(x, y);
- w = wth;
- clr = c;
- oppacity = o;
- alive = true;
- }
- public void reproduce()
- {
- if(w > 1)
- {
- for(int i = 0; i < 2; i++)
- {
- float newX = position.x + random(-w, w);
- float newY = position.y + random(-w/2, w/4);
- float r = random(10);
- float newW = w - r;
- if(newW < 1)
- newW = 1;
- particles.add(new Particle(newX, newY, newW, clr, oppacity));
- alive = false;
- }
- }
- }
- public void drawParticle()
- {
- fill(clr, oppacity);
- ellipse(position.x, position.y, w, w);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement