// Example by Tom Igoe import processing.serial.*; // constants int MINSIZE = 100; int MAXSIZE = 640; // global variables int inByte; float rectSize = MINSIZE; Serial myPort; // The serial port int dataCount = 0; void setup() { // List all the available serial ports println(Serial.list()); // I know that the first port in the serial list on my mac // is always my Keyspan adaptor, so I open Serial.list()[0]. // Open whatever port is the one you're using. myPort = new Serial(this, Serial.list()[1], 57600); size(1280, 800); rectMode(CENTER); } void draw() { background(255); fill(0); rect(width/2, height/2, rectSize, rectSize); // rectSize --; rectSize = constrain(rectSize-(float)Reciprocal_Logarithmic_model(rectSize), MINSIZE, MAXSIZE); if (rectSizeheight)rectSize=height; dataCount++; println("data count: " + dataCount); // if(inByte>intensity)intensity = inByte; // intensity=int((inByte-120)*3.5); // if (intensity < 0 ) intensity = 0; // if (intensity > 255) intensity = 255; // println(":" + intensity); } double Logarithmic_model(double x_in) { //log model from zunzun.com //fit to data points // 100, 40 // 2000, 1 double temp; temp = 0.0; // coefficients double a = -2.8159001580415367E+02; double b = 5.8035502766356771E+01; temp = a + b*Math.log(x_in); return temp; } double Reciprocal_Logarithmic_model(double x_in) { //reciprocal log model from zunzun.com //fit to data points // 100, 0 // 640, 40 double temp; temp = 0.0; // coefficients double a = 3.4188147348130071E+00; double b = -5.2523894603906762E-01; temp = 1.0 /(a + b*Math.log(x_in)); return temp; }