Loading...
Logo
Processing Forum
madscien's Profile
1 Posts
0 Responses
0 Followers

Activity Trend

Last 30 days

Loading Chart...

Show:
Private Message
    Dear all processing masters,

    I am new to this amazing tool and designing a conceptual social network prototype, basically want to create an interface where user generated particles can be stored into one big vision, and individual particles can also connected/grouped with lines according to their color/alpha/velocity value's similarity, therefore to create a particle network-

    sounds kind of complicated but I have tried to create this customizable particle system where user can play with and sort of expressing their feelings with the motion visualization:

    ParticleSystem ps;
     int pHue = 255;
     int pSat = 255;
     int pSize = 8;
     int pShape= 1;
     float pSpeed = 1;
    float xo;
    float yo;

    void setup() {
      
      xo = width/2;
      yo = height/2;
      
      size(800,800);
      smooth();
      ps = new ParticleSystem(new PVector(width/2,width/2));
      frameRate = 24;
      colorMode(HSB);
    }

    void draw() {
      smooth();
    //  translate(xo, yo);
      
     
      
      pHue = mouseX/3;
      pSat = mouseY/2;
      background(0);
      ps.addParticle();
      ps.run();
    }




    // A simple Particle class

    class Particle {
      PVector location;
      PVector velocity;
      PVector acceleration;
      float lifespan;

      Particle(PVector l) {
        acceleration = new PVector(0,0.00);
        velocity = new PVector(random(-pSpeed,pSpeed),random(-pSpeed,pSpeed));
        location = l.get();
        lifespan = 200.0;
      }

      void run() {
        update();
        display();
      }

      // Method to update location
      void update() {
        velocity.add(acceleration);
        location.add(velocity);
        lifespan -= 1.0;
      }

      // Method to display
      void display() {
        stroke(255, 255,lifespan,0);
        fill(pHue,pSat,lifespan,200);
       
       //decide and create shape
         
       if (pShape == 1) {
       ellipse(location.x,location.y,pSize,pSize);
       }
       
       if (pShape == 2) {
       rect(location.x,location.y,pSize,pSize);
       }
       
       if (pShape == 3) {
       triangle(location.x-pSize,location.y-pSize,location.x+pSize, location.y-pSize,location.x,location.y);

       }
       
        
        }
      
      // Is the particle still useful?
      boolean isDead() {
        if (lifespan < 0.0) {
          return true;
        } else {
          return false;
        }
      }
    }


    //void mouseDragged() {
    //  xo = xo + (mouseX - pmouseX);
    //  yo = yo + (mouseY - pmouseY);
    //}

    // A class to describe a group of Particles
    // An ArrayList is used to manage the list of Particles 

    class ParticleSystem {
      ArrayList<Particle> particles;
      PVector origin;

      ParticleSystem(PVector location) {
        origin = location.get();
        particles = new ArrayList<Particle>();
      }

      void addParticle() {
        particles.add(new Particle(origin));
      }


      void run() {
        Iterator<Particle> it = particles.iterator();
        while (it.hasNext()) {
          Particle p = it.next();
          p.run();
          if (p.isDead()) {
            it.remove(); 
          }
        }
      }
    }


    void keyPressed () {
      if (key == CODED) {
        if (keyCode == UP) {
          pSize++;
          } 
          
          else if (keyCode == DOWN) {
          pSize -= 1;
          }
      
          else if (keyCode == RIGHT) {
          pSpeed += 0.2;
          } 
        
          else if (keyCode == LEFT) {
          pSpeed -= 0.2;
          }

          else if (keyCode == SHIFT) {
          pShape = 1;
          }
          else if (keyCode == CONTROL) {
          pShape = 2;
          }
          else if (keyCode == ALT) {
          pShape = 3;    
        
      }
      
    }
    }


    it's very basic at the moment, but it will be really cool if people can save the result after modifying the shape/color/velocity etc. and a collection of particles network would be generated in one space...

    Please help build up this beautiful vision of people's feelings network using simply customizable particle systems...

    Thanks a lot!
    - Madscien