I am a new user of Processing and I am trying to create a sketch whereby a series of agents follow a point that is the average location of motion (as per Daniel Shiffman Learning Processing Example 16-7).
I am attempting to combine this logic with Genware Tutorial 16, where a Vec3D follows the mouse, by replacing the mouseLoc with the average location of motion.
Is this possible? Or obvious? or a better way to do this. I think I am missing something behind the logic here...
Any help appreciated.
Sketch below.
Thanks!
////////////////////////////////////////// Follow Location of Motion.
import toxi.geom.*; import processing.video.*;
Capture video; PImage prevFrame;
float threshold = 30;
Agent a;
void setup() { size(600, 600); smooth();
Vec3D startLoc = new Vec3D (width/2, height/2, 0); a = new Agent(startLoc);
// Using the default capture device video = new Capture(this, width, height, 15); // Create an empty image the same size as the video prevFrame = createImage(video.width, video.height, RGB); } void draw() { background(0); a.run();
// image(video, 0, 0); // VIDEO IMAGE DOES NOT NEED TO BE DISPLAYED
// Capture video if (video.available()) { // Save previous frame for motion detection!! prevFrame.copy(video, 0, 0, video.width, video.height, 0, 0, video.width, video.height); prevFrame.updatePixels(); video.read(); }
// These are the variables we'll need to find the average X and Y float sumX = 0; float sumY = 0; int motionCount = 0;
// Begin loop to walk through every pixel for (int x = 0; x < video.width; x++ ) { for (int y = 0; y < video.height; y++ ) { // What is the current color color current = video.pixels[x+y*video.width];
// What is the previous color color previous = prevFrame.pixels[x+y*video.width];