PImage b, c; float x,y; // variables for position float last_x, last_y; float r, theta, curr_r; // variables for sacaddic motion float last_z, z, curr_z; float t; static float d_t=1.0/24.0; static float saccade_length = 0.1; int win_width; int win_height; // Set to 4 for 1/4 size Preview static int DIV = 1; // variables for logging of timing String outpath="output\\s_ff_blur_02\\"; PrintWriter output; static boolean writeToFile=false; void setup() { size(screen.width/DIV, screen.height/DIV);//, 800); background(0); stroke(255); noFill(); rectMode(CENTER); //b=loadImage("C:\\Swap\\Photos\\03_washington dc bedroom 2.jpg"); b=loadImage("C:\\Swap\\Photos\\01_06_western landscape.jpg"); win_height=int(b.height*0.4/DIV); win_width=int(b.width*0.4/DIV); x=0; y=int(random(b.height-win_height)/2+b.height/2); last_x=x; last_y=y; r=random(80, 300); last_z=1.0; z=random(0.5, 2.0); theta=(TWO_PI+HALF_PI*random(-0.95, 0.95))%TWO_PI; frameRate(24); if(writeToFile) { // setup up timing log file output = createWriter(outpath+"timing.txt"); }; } void draw() { if(t > saccade_length) { last_x=x; last_y=y; r=random(30, 100); last_z=z; z=constrain(last_z*random(0.9, 1.1), 0.5, 2.0); theta=(TWO_PI+HALF_PI*random(-0.95, 0.95))%TWO_PI; next_x=last_x+cos(theta)*r; next_y=last_y+sin(theta)*r; t=0.0; }; // update motion t+=d_t; curr_r=lerp(0, r, 1.0-(t/saccade_length)); curr_z=lerp(last_z, z, (t/saccade_length)); float d_x=(cos(theta)*curr_r); float d_y=(sin(theta)*curr_r); x+=d_x; y+=d_y; y=constrain(y, 0, b.height-win_height); // end condition if(x+win_width>b.width) { t=0.0; x%=(b.width-win_width); // if(writeToFile) { // output.flush(); // Writes the remaining data to the file // output.close(); // Finishes the file // }; // exit(); }; c = b.get(round(x), round(y), round(win_width/curr_z), round(win_height/curr_z)); hist_eq(c); blend(c, 0, 0, win_width, win_height, 0, 0, width, height, BLEND); line(width/2, height/2, width/2+d_x, height/2+d_y); rect(width/2, height/2, curr_z*100, curr_z*100); if(writeToFile) { saveFrame(outpath+"03_washington dc bedroom 2-#####.tif"); output.println(frameCount+" "+millis()); }; } void hist_eq(PImage in) { // equalize histogram to maximize contrast in.loadPixels(); int dimension = (in.width*in.height); // create histogram int [] hist = new int[256]; for(int i=0;i> 16) & 0xFF; // Faster way of getting red(rgb) int g = (argb >> 8) & 0xFF; // Faster way of getting green(rgb) int b = argb & 0xFF; // Faster way of getting blue(rgb) int intensity=round((r+g+b)/3.0); hist[intensity]++; }; // create cumulative distribution function // record min + max int [] cdf = new int[256]; int sum=0; int min_cdf=0; int max_cdf=0; boolean found_min=false; boolean found_max=false; for(int i=0;i<256;i++) { sum+=hist[i]; cdf[i]=sum; if((found_min==false) && (sum>0)) { min_cdf=i; found_min=true; }; if((found_max==false) && (sum>=dimension)) { max_cdf=i; found_max=true; }; }; // loop over pixels and replace with equalized vals for(int i=0;i> 24) & 0xFF; int r = (argb >> 16) & 0xFF; // Faster way of getting red(rgb) int g = (argb >> 8) & 0xFF; // Faster way of getting green(rgb) int b = argb & 0xFF; // Faster way of getting blue(rgb) // intensity normalization equation from // http://en.wikipedia.org/wiki/Histogram_equalization a = (a >> 1) << 24; r = constrain(int(norm(r, min_cdf, max_cdf)*255), 0, 255) << 16; g = constrain(int(norm(g, min_cdf, max_cdf)*255), 0, 255) << 8; b = constrain(int(norm(b, min_cdf, max_cdf)*255), 0, 255); color new_rgb = a | r | g | b; in.pixels[i]= new_rgb; }; in.updatePixels(); };