Hello,
I am trying to use the PrintWriter function to export a list of points (printIn values) which are created from a color tracking sketch, but every time the .txt file is blank. How can I get the .txt to list the points?
Any help would be appreciated.
Thanks.
import processing.video.*;
Capture cam;
PGraphics img;
PrintWriter output;
color selected = color(0,255,0); // selected color
void draw()
{
if (cam.available()) {
cam.read(); cam.loadPixels();
// pick a different selected color, if you want
if(mousePressed) selected = cam.pixels[mouseX+mouseY*cam.width];
// search for the pixel closer to the selected color
int sx = 0, sy = 0; // selected position
float minDist = 1000; // put a huge number so we do not have to care
for(int y = 0; y < cam.height; y ++) {
for(int x = 0; x < cam.width; x ++) {
color c = cam.pixels[x+y*cam.width];
float d = dist(red(c),green(c),blue(c),
red(selected),green(selected),blue(selected));
if(d < minDist) { minDist = d; sx = x; sy = y; }
}
}
// draw the cam image and on top of that draw the painted image
image(cam,0,0);
image(img,0,0);
noFill(); stroke(200,255,200); strokeWeight(5);
ellipse(sx,sy,50,50);
println("sx = "+sx+", sy = "+sy);
output.println("sx = "+sx+", sy = "+sy); // Write the coordinate to the file
}
}
void keyPressed() {
// clear
if(key == ' ') img = createGraphics(cam.width,cam.height,JAVA2D);
output.flush(); // Writes the remaining data to the file
output.close(); // Finishes the file
exit(); // Stops the program
}
Hello,
I would like to create a list of points which were created from the following sketch. I am new to processing so I don't know how to print() my results. The points would be the center points of the circles generated from the sketch. Any advice would be great.
Thanks.
import processing.video.*;
Capture cam;
PGraphics img;
color selected = color(0,255,0); // selected color
void draw()
{
if (cam.available()) {
cam.read(); cam.loadPixels();
// pick a different selected color, if you want
if(mousePressed) selected = cam.pixels[mouseX+mouseY*cam.width];
// search for the pixel closer to the selected color
int sx = 0, sy = 0; // selected position
float minDist = 1000; // put a huge number so we do not have to care
for(int y = 0; y < cam.height; y ++) {
for(int x = 0; x < cam.width; x ++) {
color c = cam.pixels[x+y*cam.width];
float d = dist(red(c),green(c),blue(c),
red(selected),green(selected),blue(selected));
if(d < minDist) { minDist = d; sx = x; sy = y; }
}
}
// draw the cam image and on top of that draw the painted image
image(cam,0,0);
image(img,0,0);
noFill(); stroke(200,255,200); strokeWeight(5);
ellipse(sx,sy,5,5);
}
}