SHARE
TWEET

Untitled

a guest Jul 19th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Particle{
  2.   PVector loc, vel, acc;
  3.   int lifeSpan, passedLife;
  4.   boolean dead;
  5.   float alpha, weight, weightRange, decay, xOffset, yOffset;
  6.   color c;
  7.    
  8.   Particle(float x, float y, float xOffset, float yOffset){
  9.     loc = new PVector(x,y);
  10.      
  11.     float randDegrees = random(360);
  12.     vel = new PVector(cos(radians(randDegrees)), sin(radians(randDegrees)));
  13.     vel.mult(random(5));
  14.      
  15.     acc = new PVector(0,0);
  16.     lifeSpan = int(random(30, 90));
  17.     decay = random(0.75, 0.9);
  18.     c = color(255,random(255),random(255));
  19.     weightRange = random(3,50);
  20.      
  21.     this.xOffset = xOffset;
  22.     this.yOffset = yOffset;
  23.   }
  24.    
  25.   void update(){
  26.    
  27.     if(passedLife>=lifeSpan){
  28.       dead = true;
  29.     }else{
  30.       passedLife++;
  31.     }
  32.      
  33.     alpha = float(lifeSpan-passedLife)/lifeSpan * 70+50;
  34.     weight = float(lifeSpan-passedLife)/lifeSpan * weightRange;
  35.      
  36.     acc.set(0,0);
  37.      
  38.     float rn = (noise((loc.x+frameCount+xOffset)*0.01, (loc.y+frameCount+yOffset)*0.01)-0.5)*4*PI;
  39.     float mag = noise((loc.y+frameCount)*0.01, (loc.x+frameCount)*0.01);    
  40.     PVector dir = new PVector(cos(rn),sin(rn));
  41.    
  42.     acc.add(dir);
  43.     acc.mult(mag);
  44.      
  45.     float randDegrees = random(360);
  46.     PVector randV = new PVector(cos(radians(randDegrees)), sin(radians(randDegrees)));
  47.     randV.mult(0.5);
  48.     acc.add(randV);
  49.      
  50.     vel.add(acc);
  51.     vel.mult(decay);
  52.     vel.limit(3);
  53.     loc.add(vel);
  54.   }
  55.    
  56.   void display(){
  57.     strokeWeight(weight+1.5);
  58.     stroke(0, alpha);
  59.     point(loc.x, loc.y);
  60.      
  61.     strokeWeight(weight);
  62.     stroke(c);
  63.     point(loc.x, loc.y);
  64.   }
  65. }
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. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top