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 setup()
{
size(640,480);
smooth();
cam = new Capture(this,640,480);
img = createGraphics(640,480,JAVA2D);
}
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; }
}
}
// update the painted image
img.beginDraw();
img.smooth();
img.fill(selected,100); img.noStroke();
img.ellipse(sx,sy,5,5);
img.endDraw();
// 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);
}
}
void keyPressed() {
// clear
if(key == ' ') img = createGraphics(cam.width,cam.height,JAVA2D);
}
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 setup()
{
size(640,480);
smooth();
cam = new Capture(this,640,480);
img = createGraphics(640,480,JAVA2D);
}
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; }
}
}
// update the painted image
img.beginDraw();
img.smooth();
img.fill(selected,100); img.noStroke();
img.ellipse(sx,sy,5,5);
img.endDraw();
// 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);
}
}
void keyPressed() {
// clear
if(key == ' ') img = createGraphics(cam.width,cam.height,JAVA2D);
}
1