//Combined code from "Fibers" and "Movement Wandering" //This sketch studies arrays and their use for weighted random function float x; float y; int p = 99; //Probability factor (maximum array index). boolean toggleLoop = true; void setup() { size(600, 400); smooth(); background(0); frameRate (120); x = width/2; y = height/2; } void draw() { fill(0, 1); //rect(0, 0, width, height); //Comment out rectangle to switch off tracer. stroke (random(225, 255), random (175, 200), random (150), random(8)); //stroke (200,200, random(200, 225), random (16)); line (x, y, x+random(-100, 100), y+random(-100, 100)); int a = int(random(0, p)); int b = int(random(0, p)); //Change p (in setup) to alter probability of each array element. float[] r = {random(-70,70),random(-1,1),random(-2,2),random(-3,3),random(-4,4), random(-5,5),random(-6,6),random(-7,7),random(-8,8),random(-9,9), 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0}; //100 elements = 1 % probability for each element. //Note: limit wander parameter to single numeric pair for grid effect. x = x + r[a]; y = y + r[b]; // a and b call random index from array. if (x >= width) { //Constrain motion. x = x - 1; } if (x <= width-width) { x = x + 1; } if (y >= height) { y = y - 1; } if (y <= height-height) { y = y + 1; } } // Mouse toggle code by amnon.owed // http://forum.processing.org/topic/mouse-toggle-loop // Place boolean toggleLoop = true; above setup. void mousePressed() { if (mouseButton == LEFT) { if (toggleLoop) { noLoop(); toggleLoop = false; } else { loop(); toggleLoop = true; } } }