// Diffusion by Phillip Granke 2006 // Click mouse over screen to start // Click to change colors // // // The program creates a screen of pixels that // output to neighboring pixels. Each pixel has // a changing weight it assigns to its neighbors' // imputs. The pixels colors is an average of the // imputs * that imputs weight. The user interface // only changes the color around a 4 pixel radius // from the mouse. // int pixel = 6; // Size of the pixel some pixel to screen size combos cause problems // float calc; //assigned distance calculation float col; //color of pixel int posNeg; // changes between 0,255 int[] Xpos; // array of Xpositions int[] Ypos; // array of Ypositions float[] RW; // array of right weights float[] LW; //array of left weights float[] UW; // array of up wieghts float[] DW; // array of down weights float[] Output; // array of outputs int pos; // ammount of positions int xpos; // ammount of x positions int ypos; // ammount of y positions int counter = 0; // counter for filling Xpos Ypos arrays int hlfpx; // half of the pixel void setup() { //setup size (666,666); background (255); rectMode(CENTER); noStroke(); //define varaibles to pixel size xpos = width/pixel; ypos = height/pixel; pos = xpos*ypos; hlfpx = pixel/2; //define array length to pixel and screen size Xpos = new int[pos]; Ypos = new int[pos]; RW = new float [pos]; LW = new float [pos]; DW = new float [pos]; UW = new float [pos]; Output = new float[pos]; //fill weights arrays with value 1 //starts the network at white (255) //fill X,Ypos arrays for (int k=hlfpx;k0) { left = Output[i-1]; } else { left = Output[pos-1]; } //define the pixel imput from above if (i-xpos>0) { up= Output[i-xpos]; } else { up= Output[i+pos-xpos-1]; } // // weights the imputs right=right*RW[i]; left=left*LW[i]; up=up*UW[i]; down=down*DW[i]; // // set color as an average of the imput colors col = ((left+right+down+up)/4); // // calculate the distance from pixel i to mouse calc = dist(Xpos[i],Ypos[i],mouseX,mouseY); // // if the mouse is within the mouse range set its output to // blkwht (0-255). if not set it to the average (col) if (calc 0) { posNeg = 0; } else { posNeg = 255; } }