Face Tracking Project - 6
Having created the particle system (see blog post Face Tracking - 5) there were three things left for me to do with this project. The first was to place the particle system within the installation, secondly modify the particle system so that it was a lot more random and lastly change the design of the particles. All of these tasks have been completed.
The first task was completed by adding the code seen within the previous blog post into the code that I had already. At first it was not working, but this is because of the part of the code that actually runs the code was not placed in the correct place. Adding this code with in the circle void, which is as the name suggests the part of the code which deals with the circle, allows the particle system to begin running and also spawn from within the circle.
The second and third tasks where done very easily. Firstly in terms of the redesign of the particles I wanted them to link to the main object so I have given each particle a random colour so that there is a link. Along with that to give them more life I have given them random sizes and made it so that there size with change throughout the particles life. This I believe adds more to the installation. In terms of the final task which was changing the physics that controls the particles, it was simply as case of trail and error until I found what I believed worked best. There is a much higher level of randomness to each particle unlike in the previous blog post, this has been done to simply breath more life into the installation and make it feel more alive.
A small example of how the installation works
The Code
import processing.video.*;
import gab.opencv.*;
import java.awt.Rectangle;
OpenCV opencv;
Capture cam;
Rectangle[] faces;
Particle p;
PVector centreLeft, track;
boolean sketchFullScreen() {
return true;
}
ArrayList<Particle> particles;
void setup() {
//setting up the canvas and cam
//size(1920, 1080);
size(displayWidth, displayHeight);
centreLeft = new PVector(587,191);
cam = new Capture(this, 700,500);
cam.start();
opencv = new OpenCV(this, cam.width, cam.height);
opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);
//declaring the particles arraylist
particles = new ArrayList<Particle>();
}//end of VoidSetup
void captureEvent(Capture cam) {
cam.read();
}//end of void captureEvent
void draw() {
background(0);
opencv.loadImage(cam);
faces = opencv.detect();
//below is to with the face tracking
if (faces != null) {
for (int i = 0; i < faces.length; i++) {
noStroke();
track = new PVector(width-map(faces[i].width/2+faces[i].x,0,cam.width,0,width), map(faces[i].height/2+faces[i].y,0,cam.height,0,height));
circle();
}//end of for
}//end of if
}//end of void draw
class Particle {
PVector location;
PVector velocity;
PVector acceleration;
float lifespan;
Particle(PVector l) {
//the behaviour of the particles
if (faces.length >=1){
acceleration = new PVector(0,random(0.05,0.25));
velocity = new PVector(random(-2.5,2.5),random(-2.5,2.5));
location = l.get();
lifespan = random(100,250);
}//end of IF
}//end of Particle(PVector)
void run() {
//this makes the particles actually run
update();
display();
}//end of void run
void update() {
velocity.add(acceleration);
location.add(velocity);
lifespan -= 3.0;
}//end of void update
void display() {
//the visual aspects of each particle
noStroke();
fill(random(255),random(255),random(255));
ellipse(location.x,location.y,random(3,13),random(3,13));
}//end of void display
boolean isDead() {
//ensuring that when the particles lifespan has finished it goes of the screen
if (lifespan < 0.0) {
return true;
} else {
return false;
}
}//end of boolean
}//end of class Particle
void circle(){
//tracking for the circle
PVector newLocLeft = track.get();
newLocLeft.sub(centreLeft);
newLocLeft.add(centreLeft);
//below is the code for the main circle
noStroke();
fill(random(255),random(255),random(255));
ellipse(newLocLeft.x, newLocLeft.y,140,140);
noStroke();
fill(0);
for(int i =0; i<50; i++){
ellipse(newLocLeft.x, newLocLeft.y, 125,125);
noStroke();
fill(random(255),random(255),random(255));
ellipse(newLocLeft.x, newLocLeft.y, 110,110);
noStroke();
fill(0);
ellipse(newLocLeft.x, newLocLeft.y, 95,95);
}
//code so that the particles are working and are being produced from the centre of the circle
particles.add(new Particle(new PVector(newLocLeft.x + random(1,20), newLocLeft.y +random(1,20))));
for (int i = 0; i < particles.size(); i++) {
Particle p = particles.get(i);
p.run();
if (p.isDead()){
particles.remove(i);
}//end of If
}//end of for
}//end of void circle
No comments:
Post a Comment