Skip to content

Instantly share code, notes, and snippets.

@jessherzog
Created March 28, 2016 20:10
Show Gist options
  • Save jessherzog/f6c3b9d22efa6de76e22 to your computer and use it in GitHub Desktop.
Save jessherzog/f6c3b9d22efa6de76e22 to your computer and use it in GitHub Desktop.
visual repair
// 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;
// writing and reading serial port data
int[] serialInArray = new int[6]; // store list of values
int serialCount = 0; // num of values recieved
boolean firstContact = false;
int temp;
int piezo;
int pixelRes = 10;
long nS = (long) random(12345);
void setup() {
size(480, 360, P2D);
smooth();
webcam = new Capture(this, width, height, 24);
webcam.start();
String portName = "/dev/cu.usbmodem1411";
port = new Serial(this, portName, 9600);
port.bufferUntil('\n')
}
void serialEvent(Serial port) {
String input = port.readStringUntil('\n');
if (input != null) {
println(input);
}
}
void draw() {
input = trim(input);
int sensors[] = int(split(input, ','));
for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) {
print ("Sensor " + sensorNum + ": " + sensors[sensorNum] + "\t");
}
image(webcam, 0, 0);
// piezo
//float p = piezo * 2000;
//if (!(piezo > 400 || piezo < 410)) {
// noiseSeed(nS);
// pixelNoise();
// nS = (long) random(p);
//}
// temp
float t;
if (input >= 100) {
t = 6;
} else {
t = 0;
}
filter(BLUR, t);
}
void captureEvent(Capture webcam) {
webcam.read();
}
void pixelNoise() {
image(webcam, 0, 0);
float yOff = 0;
for (int x=0; x<webcam.width; x +=pixelRes) {
float xOff=0;
for (int y=0; y<webcam.height; y+=pixelRes) {
color c = webcam.get(x+pixelRes/2, y+pixelRes/2);
fill(c);
stroke(255, 50);
float ns = noise(xOff, yOff);
if (ns > 0.5) {
fill(c);
noStroke();
rect(x, y, pixelRes, pixelRes);
}
ns = noise(xOff-0.8, yOff+0.7);
if (ns>0.7) {
fill(255);
noStroke();
rect(x, y, pixelRes, pixelRes);
}
xOff += 0.05;
}
yOff += 0.06;
}
}
void saveImage()
{
saveFrame("images/captured-####.jpg");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment