// Program draws a black square in the middle of the screen. // It reacts to multiple key-presses, growing. // Constants int MININTERVAL = 100; float MULTIPLIER = 0.00004; float MINSIZE = 100.; float MAXSIZE = 640.; int XSIZE = 640; int YSIZE = 800; 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.; // Program void setup() { // size(200, 200); size(XSIZE, YSIZE); // rectMode(CENTER_DIAMETER); noStroke(); fill(0); background(255); } void loop() { i++; if (i > CONTRACTPERIOD) { i=0; background(255); //cursize = max(MINSIZE, float(Logarithmic_model(hitinterval))); hitinterval+=INCREMENT; // cursize = max(MINSIZE, cursize-(cursize*cursize*MULTIPLIER));//INCREMENT);//float(Logarithmic_model(hitinterval))); // cursize = max(MINSIZE, cursize-float(Reciprocal_Logarithmic_model(cursize)));//INCREMENT);//float(Logarithmic_model(hitinterval))); cursize = constrain(cursize-Reciprocal_Logarithmic_model(cursize), MINSIZE, MAXSIZE); } rect(XSIZE/2, YSIZE/2, cursize, cursize); } float Logarithmic_model(float x_in) { //log model from zunzun.com //fit to data points // 100, 40 // 2000, 1 double temp; temp = 0.0; // coefficients float a = 9.9952499373538743E+01; float b = -1.3018519827118025E+01; temp = a + b*Math.log(x_in); return (float)temp; } float Reciprocal_Logarithmic_model(float x_in) { //reciprocal log model from zunzun.com //fit to data points // 100, 0 // 640, 40 float temp; temp = 0.0; // coefficients float a = 3.4188147348130071E+00; float b = -5.2523894603906762E-01; temp = (float)(1.0 /(a + b*Math.log(x_in))); return temp; } void mousePressed() { hits++; int timenow = millis(); hitinterval = (timenow-timelasthit); print(hitinterval + " - "); timelasthit = timenow; lastsize = cursize; cursize = constrain(cursize + (float)Logarithmic_model(hitinterval), MINSIZE, MAXSIZE); println(cursize); }