• fullscreen
  • Part.pde
  • sketch_dic22a.pde
  • class Part 
    {
      PVector l; 
      PVector v; 
      PVector a; 
      float m; 
      float RMIN;
      float RMAX;
      int cl = 0;
      
      Part(PVector l,PVector v,PVector a, float m)
      {
        this.l = l;
        this.v = v;
        this.a = a;
        this.m = m;
      }
      
      void live()
      {
        update();
      }
      
      void update()
      {
      v.add(a);
      l.add(v);
      a.x = 0.0f; 
      a.y = 0.0f; 
      
      // disegna
      float col = map(m, 1, 10, 1, 360);
      stroke(col, 100, 100, 10);
      //print(col+" ");
      point(l.x, l.y);  
      }
      
      boolean pop() { 
        if (((l.x > width-0) || (l.x < 0)) || ((l.y > height-0) || (l.y < 0))){ 
          return true;
        }
        else return false;   
      }  
      
      void setLoc(PVector v) {
        l = v;
      }
    
      void setVel(PVector v) {
        v = v;
      }
    
      void setAcc(PVector v) {
        a = v;
      }
      
      void add_force(PVector force) {
        force.div(m);  
        a.add(force); 
      } 
      
      PVector getVel() { 
        return v; 
      } 
     
      PVector getAcc() { 
        return a; 
      } 
     
      PVector getLoc() { 
        return l; 
      } 
    }  
    
    
    int PMAX = 35000;
    ArrayList p = new ArrayList(PMAX);
    //Part[] p = new Part[20000];
    float speed = 0;
    float yCoord = 0;
    float myr;
    float c = 0.0; 
    boolean drawbg = true;
    void setup() 
    { 
      size(800,600, P2D); 
      //smooth(); 
      colorMode(HSB, 360, 100, 100, 100);
      for(int i=0; i<PMAX; i++){ 
        PVector a = new PVector();  
        PVector v = new PVector();   
        PVector l = new PVector(random(10, width-10),random(10, height-10)); 
        float m = random(1, 10);
      
      
      
    //    float r = noise(off)*60; // estrae un numero che vale 1/2 di di r
    //    off += 0.01;
    //    print("  " + r);
    
    
       p.add(new Part (l, v, a, m));
      } 
      
    } 
    
    void draw()
    {
      //background(1, 0, 100, 100);
      noStroke();
      fill(1, 100, 0, 75);
      rect(0, 0, width, height);
    
      yCoord += speed;
      speed += 0.01;
      stroke(1, 0, 100, 50);
      line(1,yCoord, 4, yCoord);
      line(width-4,yCoord, width-2, yCoord);
      
      
      float progAttrito = map(yCoord, 0, height-10, -0.10, -0.80);
      c = progAttrito;
      //print(" "+c);
      if (yCoord > height-10) {
        speed = speed * -0.995;  
      }
      
      for(int i = p.size()-1; i >= 0; i--){
        Part particle = (Part) p.get(i);
        //print(" " +i);
        particle.live();
        
        // forza grav
        PVector grav = new PVector(0.0,0.40);
        particle.add_force(grav);
        
        // attrito
        PVector actualVel = particle.getVel(); 
        PVector attrito = PVector.mult(actualVel,c); 
        particle.add_force(attrito);     
    
        
    
        
        if(mousePressed == true){
        // il mouse attrae
        PVector mouseLoc = new PVector(mouseX,mouseY);
        PVector diff = PVector.sub(mouseLoc,particle.getLoc());
        diff.normalize();
          
        float factor = 0.90; 
        diff.mult(factor);
        particle.setAcc(diff);
        }
          
          if (particle.pop()) {
              p.remove(i); // rimuove
              PVector a = new PVector();  
              PVector v = new PVector();   
              PVector l = new PVector(random(10, width-10),random(100)+yCoord); 
              myr = map(yCoord, 0, height-10, 1, 10);
              p.add(new Part (l, v, a, myr)); // aggiunge
          }
      }
      //if(p.isEmpty())
       //print(" end ");
    }
    
     	
    
    void keyPressed() { 
      //saveFrame();
    }
    
    
    
    
    
    
    
    

    code

    tweaks (0)

    about this sketch

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

    license

    advertisement

    Giovanni Carlo Mingati

    magnet-ink

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

    Using the P3D renderer and an ArrayList. 35000 colored particles are created on screen (in HSB colorMode). Each particle has a different mass (depending on color, but its not really really color-dependant) and so each reacts differently to the attraction of your mouse (with mouse clicked). Each particle has a different color, given by the position of the two indicators (and proportional to mass) at the moment it's created. Progressive friction in space is also applied (look at the two white lines at left and right of the screen). When the lines are on the top section the friction is low, incre

    dotlassie
    24 Dec 2008
    Nice xmas gift :)
    It's a bit dark, but interesting shapes can be created.
    Dean Ward
    2 Jan 2009
    I love this! After playing with it for a while a thought hit me, could it be changed so that same-color particles stick together if they collide at a high enough speed, have the downwards gravity removed and create a perminent attractor somewhere on the screen? I think if those changes where made and it was left running for a while you would end up with something like a galaxy with orbiting planets, asteroids and general space dust... what do you think?
    Really beautiful to play with!
    Dean, i am working on your idea.
    Dean Ward
    8 Jan 2009
    Awesome! Cant wait to see how it turns out :D
    Thomas Duerr
    10 Jan 2009
    impressive
    Starkes
    26 May 2009
    love it
    Jack
    28 May 2009
    super cool
    Callum Rogers
    16 Sep 2009
    This is amazing. Truly amazing.
    I'm an X-men with the superpower of controlling any color of ink! WOOOOAAhh!
    Did you make any changes to the code? It stoped working for my (Chrome, Win7)
    And every other applet is working...
    I uploaded a new version just after your comment, removing noc* library and therefeore using PVector insted of Vector3d... but nothing changed. See my portfolio summer.gcmingati.net for a working version
    Thanks!
    You need to login/register to comment.