Created
July 18, 2014 16:33
-
-
Save zeroeth/6a4579d46ee8a5b2b825 to your computer and use it in GitHub Desktop.
gist
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.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