import processing.opengl.*;
import processing.serial.*;
Serial port;
float znoise = 0.0;
float derp;
color boxFill;
void setup() {
size(1000,800, OPENGL);
port = new Serial(this, "/dev/cu.usbserial-A700fiDh", 9600);
port.bufferUntil('\n');
noStroke();
}
void draw() {
float x = 0;
float y = 0;
println(derp);
if(derp>=201 && derp<=400) {
float herp = map(derp, 201, 400, 0, 1023);
if(millis()%1000 == 0){
rect(0,0,width,height);
background(#ffffff);
}
boxFill = color(random(255), random(255), random(255), random(105));
translate(400,300,0);
rotateY(random(herp));
rotateX(random(herp));
fill(boxFill);
box(random(herp), random(herp), random(.5*(herp+herp)) );
// println(herp);
}
if(derp>=0 && derp<=200) {
float herp = map(derp, 0, 200, 0, 1023);
if(herp>500) {
x=20;
y=20;
}
else if(herp>350 && herp<=500) {
x = 10;
y=10;
}
else if(herp<=350 && herp>100) {
x=6;
y=6;
}
else if(herp<=120 && herp>90) {
x=5;
y=5;
}
else if(herp<=90 && herp>60) {
x=4;
y=4;
}
else if(herp<=60 && herp>30) {
x=3;
y=3;
}
else if(herp<=30) {
x=2;
y=2;
}
float xnoise = 0.0;
float ynoise = 0.0;
for(int i=0; i<=height; i+=y) {
for(int j=0; j<=width; j+=x) {
float blah = noise(xnoise, ynoise, znoise)*256;
fill(blah);
rect(j, i, x,y);
if(key=='c' || key == 'C') {
fill(i, blah, j);
rect(j, i, x,y);
}
xnoise += 0.09;
}
ynoise += 0.09;
}
znoise += 0.09;
//println(herp);
}
}
void serialEvent (Serial port)
{
derp = float(port.readStringUntil('\n'));
}