• fullscreen
  • Particle.pde
  • perlin3d.pde
  • class Particle{
      
      PVector location;
      PVector velocity;
      PVector acceleration;
      float mass;
    
      Particle() {
        location = new PVector(random(-200, 200),random(-100,100),10);
        velocity = new PVector();
        acceleration = new PVector();
        mass = random(0.5,1.0);
      }
    
      void update() {
      velocity.add(acceleration);
      location.add(velocity);
      acceleration = new PVector();
      velocity.x = cos(noise(location.x*.02,location.y*.02, millis()*.0002)*TWO_PI); 
      velocity.y = sin(noise(location.x*.02,location.y*.02, millis()*.0002)*TWO_PI);
      }
    
      void render() {
        update();
        float cl = map(getVel().y, -0.9, 0.9, 99, 45);
        stroke(0, 100, 100, cl);
        strokeWeight(0.5f);
        line(location.x,location.y,location.z,location.x,location.y,location.z-20);
      }
      
      PVector getVel() { 
        return velocity; 
      }   
      
      void add_force(PVector force) {
        force.div(mass);  
        acceleration.add(force); 
      } 
      
      boolean pop() { 
        if (((location.x > 200) || (location.x < -200)) || ((location.y > 100) || (location.y < -100)) || ((location.z > 10) || (location.z < -10))){ 
          return true;
        }
        else return false;   
      }  
      
    }
    
    
    
    
    import peasy.*;
    PeasyCam pCamera;
    ArrayList p = new ArrayList();
    float d=127,f=0;
    void setup()
    {
      size(750, 450, P3D);
      colorMode(HSB,360, 100, 100);
      smooth();
      pCamera = new PeasyCam(this, 700);
      pCamera.setMinimumDistance(600);
      pCamera.setMaximumDistance(800);
    
      for(int i=0; i<6000; i++){ 
       p.add(new Particle());
      }
      noiseDetail(10, .2);
    }
    
    void draw()
    {
      background(1, 0, 100);
      float e = cos(PI*(f+=1)/d);
      float em = map(e, -1, 1, -1.5, -0.5);
      pushMatrix();
      fill(200, 50, 40, 2);
      strokeWeight(0.3f);
      stroke(1, 0, 0, 10);
      box(400, 200, 20);
      popMatrix();
      for(int i = p.size()-1; i >= 0; i--){
        Particle part = (Particle) p.get(i);
        part.render();    
        PVector actualVel = part.getVel();
        PVector pickup = new PVector(0.2, em, 0);
        PVector attrito = PVector.mult(actualVel, 0.5); 
        part.add_force(pickup);   
        part.add_force(attrito);        
        if (part.pop()) {
            p.remove(i);
            p.add(new Particle());      
        }
      }
    }
    
    
    
    

    code

    tweaks (0)

    about this sketch

    This sketch is running as Java applet, exported from Processing.

    license

    advertisement

    Giovanni Carlo Mingati

    perlin3D

    Add to Faves Me Likey@! 4
    You must login/register to add this sketch to your favorites.

    Perlin noise visualization + friction + gravity.

    You need to login/register to comment.