• fullscreen
  • Particle.pde
  • stippleVerletReplay.pde
  • class Particle{
      
      PVector pos;
      PVector vel;  
      PVector acc; 
      PVector force;
      float drag;
      float rad;
      float mass;
      int fllColor;
      
      public Particle(float m, PVector _pos){
       pos = _pos;
       vel = new PVector();
       acc = new PVector();
       force = new PVector();
       drag = 0.9f;
       rad = m;
       mass = m;
      }
      
      void run() {
        update();
        render();
      }  
    
      void update() {
       //vel.mult(drag);
       vel.add(force);
       pos.add(vel);
       force.div(mass);
       acc = new PVector();
       force = new PVector();
       vel.limit(0.7);
      }
    
     void add_force(PVector p) { 
        p.div(mass);
        vel.add(force);
      }  
      PVector getVelocity() {
        return vel;
      }
      void render() {
        noStroke();
        fill(fllColor);
        ellipse(pos.x, pos.y, rad*2, rad*2);
      }  
    
    
    }
    
    import pogg.*;
    TheoraMovie movie;
    
    Particle[] particles;
    PImage reference;  
    int nP = 1000;
    
    void setup(){
      size(320,240, JAVA2D);
      smooth();
      ellipseMode(CENTER);
      movie = new TheoraMovie(this, "capture.ogg");
      movie.loop();
      reference=movie;
      particles = new Particle[nP];
      for (int i = 0; i < nP; ++i) {
        particles[i] = new Particle(0, new PVector(random(width), random(height), 0));
      }
    }
    
    void draw(){
      background(255);
      movie.read();
      PVector repelforce = new PVector();
      float mag;
      float repelstrength;
      float pp;
      for (int i=0; i<particles.length; i++){
              Particle p1 = particles[i];
      	repelforce.set(p1.pos);
      	repelforce.x-=width/2;
      	repelforce.y-=height/2;
              mag = repelforce.mag();
                repelstrength = (mag - p1.mass) *-0.001;
                if(repelstrength<0) {
                     repelforce.mult(repelstrength/mag);
                     p1.force.add(repelforce);
                }
      	  if(i>=particles.length-1) continue;
      	  for(int j=i+1; j<particles.length; j++) {
                if (p1.pos.x >= 0 && p1.pos.x < reference.width && p1.pos.y >= 0 && p1.pos.y < reference.height) {
                  color pixel = reference.get((int)p1.pos.x, (int)p1.pos.y);
                  int pbr = getBrightness(pixel);      
                  p1.rad = map(pbr, 0, 220, 4.0, 0.1);
                  p1.mass = map(pbr, 0, 255, 1.0, 0.1);
                  p1.fllColor = pbr;
                }      
      		Particle p2 = particles[j];
      	        repelforce.set(p2.pos);
                      repelforce.sub(p1.pos);
      		mag = repelforce.mag();
      		repelstrength = (p2.mass*25-mag);
                      if((repelstrength>0)&&(mag>0)) {
                              repelforce.mult(repelstrength*(p1.mass/100) / mag);
      			p1.force.sub(repelforce);
      			p2.force.add(repelforce);
      		}
      	  }
              p1.run();
      
      }
    
    }
    
    int getBrightness(int c){ int r=c>>16&0xFF,g=c>>8&0xFF,b=c&0xFF; return c=(c=r>g?r:g)<b?b:c; }  
    

    code

    tweaks (0)

    about this sketch

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

    license

    advertisement

    Giovanni Carlo Mingati
    Ale
    9 Nov 2012
    Very nice job!
    Just for the record, to optimize it a little you may use this tiny brightness method:
    int getBrightness (int c)
    {
    int r=c>>16&0xFF;, g=c>>8&0xFF;, b=c&0xFF;
    return c=(c=r>g?r:g)<b?b:c;
    }
    This way you avoid processing's default brigthness method (a heavy operation that converts the color to HSB before yielding the brightness) and you avoid also casting the result. Anyway, you won't probably notice it much on the framerate... :-)
    Thanks for sharing!
    Thank you Ale. Rewrote a bit the thing, added your tiny brightness method and lowered the number of Particles. Now @320x240 it should run @12fps (at least).
    Pierre MARZIN
    23 Jan 2013
    Brilliant!
    Good job! I haven't seen it using video source yet, very vital dynamics. Thanks for sharing.
    bitcraft
    26 Jan 2013
    Nice! I'd love to see this fullscreen with some OpenGL shader tricks ...
    Reminds me of KrazyDad's StippleCam (http://joyofprocessing.com/blog/2011/11/stipple-cam/)
    and StippleCat (http://www.openprocessing.org/sketch/47364)
    You need to login/register to comment.