Skip to content

Instantly share code, notes, and snippets.

@zeroeth
Created July 18, 2014 16:33
Show Gist options
  • Select an option

  • Save zeroeth/6a4579d46ee8a5b2b825 to your computer and use it in GitHub Desktop.

Select an option

Save zeroeth/6a4579d46ee8a5b2b825 to your computer and use it in GitHub Desktop.
gist
import processing.serial.*;
Serial myPort; // Create object from Serial class
int linefeed = 10;
/**
* Mixture Grid
* modified from an example by Simon Greenwold.
*
* Display a 2D grid of boxes with three different kinds of lights.
*/
int leftSensor=0;
int rightSensor=0;
void setup() {
size(640, 360, P3D);
noStroke();
String portName = Serial.list()[1];
myPort = new Serial(this, portName, 9600);
}
void draw() {
defineLights();
background(0);
if ( myPort.available() > 0) { // If data is available,
leftSensor = Integer.parseInt(myPort.readStringUntil(linefeed)); // read it and store it in val
rightSensor = Integer.parseInt(myPort.readStringUntil(linefeed)); // read it and store it in val
}
for (int x = 0; x <= width; x += 60) {
for (int y = 0; y <= height; y += 60) {
pushMatrix();
translate(x, y);
rotateY(map(leftSensor, 0, width, 0, PI));
rotateX(map(rightSensor, 0, height, 0, PI));
box(90);
popMatrix();
}
}
}
void defineLights() {
// Orange point light on the right
pointLight(150, 100, 0, // Color
200, -150, 0); // Position
// Blue directional light from the left
directionalLight(0, 102, 255, // Color
1, 0, 0); // The x-, y-, z-axis direction
// Yellow spotlight from the front
spotLight(255, 255, 109, // Color
0, 40, 200, // Position
0, -0.5, -0.5, // Direction
PI / 2, 2); // Angle, concentration
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment