// Program draws a black square in the middle of the screen. // It reacts to multiple key-presses, growing. // Includes import processing.serial.*; // Constants int MININTERVAL = 100; float MULTIPLIER = 0.00004; float FORCE_MULTIPLIER = 90; float MINSIZE = 100.; float MAXSIZE = 640.; int XSIZE = 768; int YSIZE = 1024; int CONTRACTPERIOD = 1; int INCREMENT=10; // Program Variables int hits = 0; int i=0; int timelasthit = -2000; int hitinterval = 2000; float cursize = 100.; float lastsize = 100.; int inByte = 0; Serial myPort; // The serial port // Program void setup() { 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(200, 200); size(XSIZE, YSIZE); rectMode(CENTER); noStroke(); fill(0); background(255); } void draw() { float subtractor; subtractor = (float)Reciprocal_Logarithmic_model(cursize); cursize = constrain(cursize-subtractor, MINSIZE, MAXSIZE); // println(" - " + cursize + " - " + subtractor); background(255); rect(XSIZE/2, YSIZE/2, cursize, cursize); } 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 = 9.9952499373538743E+01; double b = -1.3018519827118025E+01; temp = a + b*Math.log(x_in); print (" - " + temp); 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 = 2.7716949837720617E-01; // double b = -3.8471867754609625E-02; double a = 3.4188147348130071E+00; double b = -5.2523894603906762E-01; temp = 1.0 /(a + b*Math.log(x_in)) + - 10; return temp; } void serialEvent(Serial myPort) { float increment; inByte = myPort.read(); print(inByte); //cursize += inByte * FORCE_MULTIPLIER; hits++; int timenow = millis(); hitinterval = (timenow-timelasthit); print(hitinterval); timelasthit = timenow; if (hitinterval < 1) hitinterval = 1; lastsize = cursize; increment = (float)Logarithmic_model(hitinterval); if(increment>40)increment=40.; cursize = constrain(cursize + increment, MINSIZE, MAXSIZE); println(" - " + cursize); } /* void mousePressed() { hits++; int timenow = millis(); hitinterval = (timenow-timelasthit); print(hitinterval); timelasthit = timenow; if (hitinterval < 1) hitinterval = 1; lastsize = cursize; cursize = constrain(cursize + (float)Logarithmic_model(hitinterval), MINSIZE, MAXSIZE); println(" - " + cursize); // inByte=myPort.read(); // cursize += inByte * FORCE_MULTIPLIER; // print(inByte + " - "); redraw(); } */