// Random Movement 1D // Display settings int picLeft = 40; int picTop = 40; int picWidth = 300; int picHeight = 300; void setup(){ size(700,400); background(204,204,182); framerate(60); loadFonts(); drawTitle(); stroke(153,153,153); } void loop(){ drawPixels(); } void drawPixels(){ //draws the pixelarray on screen float valueX = 0, valueY = 0; int lineX, lineY; int v; // cleanup right area fill(204,204,182); rect(picLeft+310, picTop, picWidth, picHeight); // x loop for (int i=1; i<=picWidth; i++){ if (i==picHeight){ lineX = picLeft + 1; // last col }else{ lineX = picLeft +i+1; // i-1 col } // y loop for (int j=1; j<=picHeight; j++){ // calculate new value from neighbour in x direction, add error if (j==picHeight){ lineY = picTop + 1; // last row }else{ lineY = picTop +j+1; // j-1 row } valueX = red(get(lineX, picTop + j)) + alter(); valueY = red(get(picLeft + i, lineY)) + alter(); //check boundaries of new values valueX = max(min(valueX,255),0); valueY = max(min(valueY,255),0); // calculate value for the pixel // mid value: v =roundme((valueX + valueY)/2); // extreme: //float difX = valueX; // float difY = valueY; //if(abs(difX) < abs(difY)){ // v = int(valueX); //}else{ // v = int(valueY); //} color c = color(v,v,v); set(picLeft+i, picTop + j, c); } // draw level indicator; set(picLeft+310+i, picTop+picHeight-int(valueX), color(255,127,0)); } } public float alter(){ // gives an error value +- float n = random(50)-25; return(n); } void drawTitle(){ // Text Caption fill(102,102,102); text("_random movement 2D", 495, 375); } void loadFonts(){ BFont Univers65; Univers65 = loadFont("Univers65.vlw.gz"); textFont(Univers65, 18); } public int roundme(float i){ // round correctly (unless i find the java round function) int ii = int(i); float r = i-ii; if (r <.5){ return ii;} else{ return ii+1;} }