Friday 16 January 2015

Design Iterations - Face Tracking Project

Face Tracking Project - 5


Moving on from the previous blog post (see post Face Tracking - 4) I have one more part to complete for my circle tracking project, which is the particle system. I had been pushed towards looking at Daniel Shiffman's particle systems by lecturer and this has pretty much solved the problem. I have found a website created by Daniel Shiffman called the Nature of Code. This in terms of learning about processing is simply a gold mine. Within this website there was a large part of particle systems. 


Using this website I was able to create a particle system that I will implement within my installation. It is a simple system where particles are spawned into the world from a designated position, which in my case will be the middle of the circle, and then these particles go about their "lives". The code has been written so that each particle is affected differently by the physical elements, such as gravity, and each one has its own random life span. This means one particle can remain on the screen for up to 10 seconds and others will die within 2. Below is the particle system that has been made. 




I will edit this particle system to make the physics within in more random, which should make the particles act more individual instead of all mostly doing the same thing. I will also change the design of the particle to make it more visually appealing. 

The code 

Particle p;
ArrayList<Particle> particles;
void setup() {
  size(640,360);
  particles= new ArrayList<Particle>();
}
void draw() {
  background(255);
  particles.add(new Particle(new PVector(width/2,50)));
  for (int i = 0; i < particles.size(); i++) {
    Particle p = particles.get(i);
    p.run();
    if (p.isDead()){
      particles.remove(i);
    }
  }
}
class Particle {
  PVector location;
  PVector velocity;
  PVector acceleration;
  float lifespan;
  Particle(PVector l) {
    acceleration = new PVector(0,0.05);
    velocity = new PVector(random(-1,1),random(-2,0));
    location = l.get();
    lifespan = 255.0;
  }
  void run() {
    update();
    display();
  } 
  void update() {
    velocity.add(acceleration);
    location.add(velocity);
    lifespan -= 2.0;
  }
  void display() {
    stroke(0,lifespan);
    fill(0,lifespan);
    ellipse(location.x,location.y,8,8);
  }
  boolean isDead() {
    if (lifespan < 0.0) {
      return true;
    } else {
      return false;
    }
  }
}

Reference List 

Shiffman, D., 2012. Chapter 4. Particle Systems. The Nature Of Code, Available from: http://natureofcode.com/book/chapter-4-particle-systems [Accessed 16 January 2015].

No comments:

Post a Comment