Created
April 1, 2016 01:28
-
-
Save jessherzog/af5d2e70ef117705fff38b1476673a8a to your computer and use it in GitHub Desktop.
STUDIO/LAB MIDTERM
This file contains 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
// get the serial lib : | |
import processing.serial.*; | |
// give port a variable : | |
Serial port; | |
// get the webcam lib : | |
import processing.video.*; | |
// give webcam a variable : | |
Capture webcam; | |
// sensors | |
int cap1, cap2, piezo, temp, axisX, axisY, axisZ; | |
// for accel filter settings | |
float x, y, z; | |
PShader shade; | |
void setup() { | |
size(480, 360, P2D); | |
smooth(); | |
webcam = new Capture(this, width, height, 24); | |
webcam.start(); | |
String portName = "/dev/cu.usbmodem1421"; | |
port = new Serial(this, portName, 115200); | |
port.bufferUntil('\n'); | |
shade = loadShader("shader.glsl"); | |
} | |
void captureEvent(Capture webcam) { | |
webcam.read(); | |
} | |
void serialEvent(Serial port) { | |
String reading = port.readStringUntil('\n'); | |
if (reading != null) { | |
reading = trim(reading); | |
int values[] = int(split(reading, ',')); | |
for (int valNum = 0; valNum < values.length; valNum++) { | |
print(values[valNum] + "|"); | |
} | |
println(); | |
if (values.length > 1) { | |
cap1 = values[0]; | |
cap2 = values[1]; | |
piezo = values[2]; | |
temp = values[3]; | |
axisX = values[4]; | |
axisY = values[5]; | |
axisZ = values[6]; | |
} | |
} | |
} | |
void draw() { | |
shade.set("brightness", 1.0); | |
// cap1, cap2 – brcosa | |
shade.set("contrast", map(cap1, 0, 128, -5, 5)); | |
shade.set("saturation", map(cap2, 0, 128, -5, 5)); | |
// piezo - threshold | piezo - pixelate | |
if (piezo >= 400 && piezo <= 410) { | |
shade.set("threshold", map(piezo, 400, 410, 0, 1)); | |
} else { | |
shade.set("pixels", 0.1 * piezo, 0.1 * piezo); | |
} | |
// temp - blur | |
float t; | |
if (temp >= 100) { //when analog pin unplugged | |
t = 6; | |
} else { | |
t = 0; | |
} | |
// axisX, axisY, axisZ - channels | |
shade.set("rbias", map(x, 2, 500, -0.2, 0.2), 0.0); | |
shade.set("gbias", map(y, 2, 500, -0.2, 0.2), 0.0); | |
shade.set("bbias", map(z, 2, 500, -0.2, 0.2), 0.0); | |
shade.set("rmult", map(x, 2, 500, 0.8, 1.5), 1.0); | |
shade.set("gmult", map(y, 2, 500, 0.8, 1.5), 1.0); | |
shade.set("bmult", map(z, 2, 500, 0.8, 1.5), 1.0); | |
// alternate color filter for axisX, axisY, axisZ | |
//int a; | |
//float rX = map(x, 2, 500, 0, 255); | |
//float gY = map(y, 2, 500, 0, 255); | |
//float bZ = map(z, 2, 500, 0, 255); | |
//// y is also alpha | |
//a = int(gY); | |
//// if x unplugged | |
//if (x > 300 && z > 100) { | |
// rX = 0; | |
//} | |
//// if z unplugged | |
//if ((x >= 45 && x <= 50) && (y >= 45 && y <= 50) && (z >= 45 && z <= 50)) { | |
// bZ = 0; | |
//} else { | |
// a = 0; | |
//} | |
//color c = color(rX, gY, bZ, a); | |
//tint(c); | |
image(webcam, 0, 0); | |
// turn on shader after all settings : | |
filter(shade); | |
// turn on blur filter : | |
filter(BLUR, t); | |
} | |
//if 'DOWN' key pressed, saveImage(); | |
void saveImage() | |
{ | |
saveFrame("images/captured-####.jpg"); | |
} | |
void keyPressed() { | |
if (key == CODED) { | |
if (keyCode == DOWN) { | |
saveImage(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment