Instantly share code, notes, and snippets.

Embed
What would you like to do?
// Introduction to Physical Computing - ITP - NYU
// Fall 2013 - Tom Igoe
// Midterm Project - Color Flute
// Abe Rubenstein + Yu Ji
// PROCESSING
import processing.serial.*;
Serial port;
int rVal = 0; // red RGB component
int gVal = 0; // green RGB component
int bVal = 0; // blue RGB component
int brushVal = 0; // size of brush
int xPos = 0;
int yPos = 0;
int xPosPrev = 0; // previous xPos (like pmouseX)
int yPosPrev = 0; // previous yPos (like pmouseY)
void setup() {
// println(Serial.list());
String portName = Serial.list()[4];
port = new Serial(this, portName, 9600);
port.bufferUntil('\n');
size(1400,800);
background(#777777);
frameRate(300); // higher for smoother movement
}
void draw() {
color c = color(rVal, gVal, bVal);
fill(c);
//strokeWeight(brushVal);
stroke(c);
strokeWeight(brushVal);
// Only draw when piezo is being blown on
if (brushVal != 0) ellipse(xPos, yPos, brushVal*1.5, brushVal*1.5);
// current position becomes previous position
xPosPrev = xPos;
yPosPrev = yPos;
}
void serialEvent (Serial port) {
String myString = port.readStringUntil('\n');
if (myString != null) {
myString = trim(myString);
int data[] = int(split(myString, '/'));
if (data.length == 6) {
rVal = data[0];
gVal = data[1];
bVal = data[2];
brushVal = data[3];
yPos = (int) map(data[4], 390, 415, 0, height);
xPos = (int) map(data[5], 395, 320, 0, width);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment