import cc.arduino.*;
import org.firmata.*;

import processing.serial.*;

Serial port;

float x;
float y;

int in_data;

void setup() {
  size(300, 300);
  port = new Serial(this, "/dev/cu.usbserial-FTBOAA5E", 9600);
  background(0, 0, 0);
  textAlign(CENTER);
}

void draw() {
  fill(255, 70);
  noStroke();
  rectMode(CORNER);
  rect(0, 0, width, height);

  if (port.available() > 0) {
    in_data = port.read();

    x = width/2 + random(-3, 3);
    y = height/2 + random(-3, 3);

    fill(255);
    rectMode(CORNER);
    rect(width/2-20, height/2-20, 40, 30);
    textSize(in_data/10);
    fill(0);
    text(in_data, width/2, height/2);

    noFill();
    stroke(random(255), random(255), 255);
    ellipse(x, y, in_data, in_data);
    rectMode(CENTER);
    noStroke();
    fill(random(150),random(150),random(150), 10);
    rect(x, y, in_data, in_data);
  }
}
