Tuesday

Sebs the man for particles!!

After much experimentation with movies and frame differencing and blob detection, I was starting to tear my hair out. I just couldn't work out how to place the codes together to make my idea work. I wanted to detect motion or change of light which then activated a video clip: Sounds easy!

I then thought I would start from the beginning and recap again about what Seb had taught us in class about particles. Why not keep my idea simple?

So after further idea generations and several thought processes, I decided to go back to basics with the code and make my installation more exciting, by thinking more about the style and layout of it rather trying to use complicated code.

I want to experiment further with the D_Particles code and when using my background (51); trick it will black out my ugly mug and leave us with pretty particles reacting to my movement:




My code looks like this:

import hypermedia.video.*;

import processing.opengl.*;
import processing.video.*;

OpenCV opencv; // Creates a new OpenCV Object

// add image to sketch
PImage particleImg;


Particle[] particles;

final int MAX_PARTICLES = 50;

void setup()
{

size(640,480);
frameRate(20);

opencv = new OpenCV( this ); // Initialises the OpenCV object
opencv.capture( 320, 240 ); // Opens a video capture stream

particles = new Particle[0];
particleImg = loadImage("ParticleBlue.png");


//





}


void draw()
{
background(0);

noStroke();
noTint();
imageMode(CORNER);

opencv.read(); // Grabs a frame from the camera


pushMatrix();
//scale(2,2);
translate(width,0);
scale(-2,2);
image( opencv.image(), 0, 0 ); // Display the difference image
background(51);
popMatrix();

opencv.absDiff(); // Calculates the absolute difference



imageMode(CENTER);

updateParticles();

makeParticles(opencv.image());

if(particles.length>MAX_PARTICLES)
particles = (Particle[]) subset(particles, particles.length-MAX_PARTICLES);

opencv.remember(); // Remembers the current frame


}

void updateParticles()
{

for(int i =0; i<200; i++) { int xpos = (int) random(img.width); int ypos = (int) random(img.height); if(brightness(img.get(xpos,ypos))>50)
{
p = new Particle(width - (xpos*2), ypos*2);
p.draw();
particles = (Particle[]) append(particles, p);
}
}
}


class Particle
{

float xPos;
float yPos;
float xVel;
float yVel;

float rotation = 0;
float spin;

float currentAlpha = 255;
float currentScale = 0.5;

float drag = 0.98;
float fadeSpeed = 1;
float shrink = 0.8;
float gravity = 0.1;

Particle(float xpos, float ypos)
{
this.xPos = xpos;
this.yPos = ypos;
this.xVel = random(-20,20);
this.yVel = random(-20,20);
this.currentScale = random(0.01,0.05);
this.currentAlpha = 255;
//this.rotation = random(0,360);
//this.spin = random(-2,-5);

}


void update()
{
xVel*=drag;
yVel*=drag;

yVel+=gravity;

xPos += xVel;
yPos += yVel;
currentAlpha -=fadeSpeed;
currentScale*=shrink;
rotation+=spin;

}

void draw()
{
if(currentAlpha<=0) return;

pushMatrix();

tint(255,currentAlpha);
translate(xPos, yPos);
scale(currentScale);
rotate(radians(rotation));
image(particleImg, 0, 0);
popMatrix();

}

}

So all I have to do now is a little bit more design and some styling and I think I'm getting there!

Just need one more final check on the Jumpman website for styling and colour tips!

0 comments:

Post a Comment