Created
July 15, 2019 11:17
-
-
Save hellocatfood/9a221755efc4a8fcbd44e8de776f0673 to your computer and use it in GitHub Desktop.
Code used for A Perfect Circle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import processing.video.*; | |
import processing.pdf.*; | |
Capture video; | |
PGraphics topLayer; | |
PGraphics topLayer2; | |
color trackColor; | |
float hue = 0; | |
int xorig=width/2, yorig=height/2; | |
int xprev=width/2, yprev=height/2; | |
int xprev2=width/2, yprev2=height/2; | |
void setup() { | |
size(1280, 720); | |
smooth(); | |
noStroke(); | |
String[] cameras = Capture.list(); | |
video = new Capture(this, 1280, 720, cameras[0]); | |
video.start(); | |
trackColor = color(255, 25, 255); | |
topLayer = createGraphics(width, height, g.getClass().getName()); | |
topLayer2 = createGraphics(width, height, PDF, "output.pdf"); | |
topLayer2.beginDraw(); | |
topLayer2.colorMode(HSB, 360, 100, 100); | |
} | |
void draw() { | |
hue = (hue + 1) % 360; | |
if (video.available()) { | |
video.read(); | |
} | |
image(video, 0, 0); | |
float worldRecord = 500; | |
int closestX = 0; | |
int closestY = 0; | |
int closestX2 = 0; | |
int closestY2 = 0; | |
for (int x = 0; x < video.width; x ++ ) { | |
for (int y = 0; y < video.height; y ++ ) { | |
int loc = x + y*video.width; | |
color currentColor = video.pixels[loc]; | |
float r1 = red(currentColor); | |
float g1 = green(currentColor); | |
float b1 = blue(currentColor); | |
float r2 = red(trackColor); | |
float g2 = green(trackColor); | |
float b2 = blue(trackColor); | |
float d = dist(r1, g1, b1, r2, g2, b2); | |
if (d < worldRecord) { | |
worldRecord = d; | |
closestX = x; | |
closestY = y; | |
closestX2 = x; | |
closestY2 = y; | |
} | |
} | |
} | |
video.loadPixels(); | |
//topLayer2.stroke(trackColor); | |
if (worldRecord < 10) { | |
topLayer2.strokeWeight(3); | |
topLayer2.stroke(hue, 100, 100); | |
if (xprev != xorig && yprev != yorig) topLayer2.line(xprev, yprev, closestX, closestY); | |
xprev = closestX; | |
yprev = closestY; | |
} | |
topLayer.beginDraw(); | |
topLayer.colorMode(HSB, 360, 100, 100); | |
if (worldRecord < 10) { | |
topLayer.strokeWeight(3); | |
topLayer.stroke(hue, 100, 100); | |
if (xprev2 != xorig && yprev2 != yorig) topLayer.line(xprev2, yprev2, closestX2, closestY2); | |
xprev2 = closestX2; | |
yprev2 = closestY2; | |
} | |
topLayer.endDraw(); | |
image(topLayer, 0, 0); | |
} | |
void mousePressed() { | |
int loc = mouseX + mouseY*video.width; | |
trackColor = video.pixels[loc]; | |
//trackColor = hue; | |
} | |
void keyPressed() { | |
if (key == 'q') { | |
topLayer2.dispose(); | |
topLayer2.endDraw(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment