Hey everyone,
First post here and I've been working with Daniel Shiffman's book and it has been great so far.
I took one of the examples that came with the processing ide by golan levin called brightness tracking and wanted to take its brightestX and brightestY variables and draw a line of all these coordinates as they change over time like one would to with the pmouseX/Y using line.
I tried to recapture the brightestX/Y variables into oldX and oldY variables so that I could call them again as so:
Code:line(oldX, oldY, brightestX, brightestY);
but it did not seem to work.
here is the full code with where i declared the oldX/Y variables (maybe they are in the wrong place?)
Code:/**
* Brightness Tracking
* by Golan Levin.
*
* Tracks the brightest pixel in a live video signal.
*/
import processing.video.*;
Capture video;
void setup() {
size(640, 480); // Change size to 320 x 240 if too slow at 640 x 480
// Uses the default video input, see the reference if this causes an error
video = new Capture(this, width, height, 30);
noStroke();
smooth();
}
void draw() {
if (video.available()) {
video.read();
image(video, 0, 0, width, height); // Draw the webcam video onto the screen
int brightestX = 0; // X-coordinate of the brightest video pixel
int brightestY = 0; // Y-coordinate of the brightest video pixel
int oldX = brightestX;
int oldY = brightestY;
float brightestValue = 0; // Brightness of the brightest video pixel
// Search for the brightest pixel: For each row of pixels in the video image and
// for each pixel in the yth row, compute each pixel's index in the video
video.loadPixels();
int index = 0;
for (int y = 0; y < video.height; y++) {
for (int x = 0; x < video.width; x++) {
// Get the color stored in the pixel
int pixelValue = video.pixels[index];
// Determine the brightness of the pixel
float pixelBrightness = brightness(pixelValue);
// If that value is brighter than any previous, then store the
// brightness of that pixel, as well as its (x,y) location
if (pixelBrightness > brightestValue) {
brightestValue = pixelBrightness;
brightestY = y;
brightestX = x;
}
index++;
}
}
stroke(2);
line(oldX, oldY, brightestX, brightestY);
}
}
please let me know if you guys need more info and i will provide it. i looked up some previous topics and the oldX method was what i found
thanks!