import processing.video.*;
int pointNum = 1500;
float nearDist = 50;
PVector[] points;
boolean[][] distMap;
Capture camera;
void setup(){
size(640, 480);
points = new PVector[pointNum];
for(int i = 0; i < pointNum; i++){
points[i] = new PVector(random(width), random(height));
}
distMap = new boolean[pointNum][pointNum];
for(int i = 0; i < pointNum; i++){
for(int j = i; j < pointNum; j++){
float d = PVector.dist(points[i], points[j]);
if(d <= nearDist){
distMap[i][j] = distMap[j][i] = true;
} else {
distMap[i][j] = distMap[j][i] = false;
}
}
}
camera = new Capture(this, width, height);
camera.start();
}
void draw(){
println(frameCount);
background(255);
stroke(0);
strokeWeight(0.3);
noFill();
camera.loadPixels();
boolean[] isBlack = new boolean[pointNum];
for(int i = 0; i < pointNum; i++){
PVector p = points[i];
color c = camera.pixels[int(p.y) * camera.width + int(p.x)];
float gray = 0.30 * red(c) + 0.59 * green(c) + 0.11 * blue(c);
if(gray < map(mouseX, 0, width, 0, 255)){
isBlack[i] = true;
} else {
isBlack[i] = false;
}
}
for(int i = 0; i < pointNum - 2; i++){
if(!isBlack[i]){continue;}
for(int j = i + 1; j < pointNum - 1; j++){
if(!isBlack[j] || !distMap[i][j]){continue;}
line(points[i].x, points[i].y, points[j].x, points[j].y);
}
}
}
void captureEvent(Capture camera){
camera.read();
}