• fullscreen
  • estrellas.pde
  • particle.pde
  • int num = 3000;
    float t;
    Coisa[] c = new Coisa[num];
    PVector[] cLoc = new PVector[num];
    PVector[] cVel = new PVector[num];
    PVector[] cAcc = new PVector[num];
    PVector[] cCor = new PVector[num];
    PVector[] initialLocation = new PVector[num];
    float[] strokeW = new float[num];
    
    void setup(){
      size(880,620,P2D);
      smooth();
    
      background(0,20,40);
      cursor(HAND);
      for(int i = 0; i<num; i++){
      // //
      cLoc[i] = new PVector(random(width),random(height));
      cVel[i] = new PVector(0.0, 0.0);
      cAcc[i] = new PVector(0.0,0.0);
      cCor[i] = new PVector(random(0,140),random(100,200),random(100,250));
    
      strokeW[i] = random(1,2);
      
      c[i] = new Coisa(cLoc[i],cVel[i],cAcc[i],cCor[i],strokeW[i]);
    
      }
     
       for(int j = 0; j<num; j++){
        initialLocation[j] = new PVector();
        initialLocation[j] = cLoc[j].get();
      }
    }
    
    void draw(){
    
    //effects//
     filter(BLUR,1);
     filter(ERODE);
     filter(DILATE);
    /////////////////
    
    //background///
     noStroke();
     fill(0,20,40,10);
     rect(0,0,width,height);
    ////////////////
    
    //particles interaction//
      for(int i = 0; i<num; i++){
        c[i].go();
        PVector m = new PVector();
        float Pdistance = dist(c[i].getLoc().x,c[i].getLoc().y,pmouseX,pmouseY);
       if(Pdistance < 50){
        m.set(mouseX,mouseY,0);
        PVector diff = PVector.sub(m,c[i].getLoc());
        diff.normalize();
        float f = 50.0;
         if(Pdistance < 25){
           f = 10.0;
         }
        diff.div(f);
        c[i].setAcc(diff);
        
       }else{
         
        PVector iL = new PVector();
        iL.set(initialLocation[i]);
        PVector diff2 = PVector.sub(iL,c[i].getLoc());
        diff2.normalize();
        float f2 = 5.2;
        diff2.div(f2);
        c[i].setVel(diff2);
        
       }
      }
    ///////////////////////
    
    }
    
    
    class Coisa{ // "Thing"
      PVector loc;
      PVector vel;
      PVector acc;
      PVector colors;
      float strokeW;
      float maxVel;
      Coisa(PVector loc_, PVector vel_, PVector acc_, PVector colors_,float strokeW_){
        loc = loc_.get();
        vel = vel_.get();
        acc = acc_.get();
        colors = colors_.get();
        strokeW = strokeW_;
        maxVel = 2000;
      }
      
      void go(){
        move();
        render();
        border();
      }
      
      void move(){
        vel.add(acc);
        loc.add(vel);
        if(vel.mag() > maxVel){
          vel.normalize();
          vel.mult(maxVel);
        }
      }
      
      void border(){
        if((loc.y > height+100) || (loc.y < -100)){
          vel.y *= -0.5;
        }
        if((loc.x < -100) || (loc.x > width+100)){
          vel.x *= -0.5;
        }
      }
      
      void render(){
        color r =(int) colors.x;
        color g =(int) colors.y;
        color b =(int) colors.z;
        strokeWeight(strokeW);
        stroke(r,g,b,100);
        point(loc.x,loc.y);
      }
      
      //geters e seters
      PVector getVel(){
        return vel.get();
      }
      
      PVector getLoc(){
        return loc.get();
      }
      
      PVector getAcc(){
        return acc.get();
      }
      
      float getMaxVel(){
        return maxVel;
      }
      
      PVector getColor(){
        return colors.get();
      }
      
      void setVel(PVector v){
        vel = v.get();
      }
      
      void setLoc(PVector v){
        loc = v.get();
      }
      
      void setAcc(PVector v){
        acc = v.get();
      }
      
      void setMaxVel(float f){
        maxVel = f;
      }
      
      void setColor(PVector v){
        colors = v.get();
      }
      
      
    }
    

    code

    tweaks (0)

    about this sketch

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

    license

    advertisement

    ignacio parada

    proceso examen

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

    You need to login/register to comment.