import controlP5.*; PImage img; ControlP5 controlP5; static float imgw = 800; static float imgh = 600; float thresh=3.0; void setup() { size(1000, 800); img = loadImage("urs_firscher_060_push.jpg"); // Load demo image background(255); controlP5 = new ControlP5(this); controlP5.addSlider("thresh") .setPosition(10,imgh+20) .setRange(0,255) .setValue(thresh) .setCaptionLabel("dark threshold"); } void randstroke() { color c; float ix, iy; float x, y; float bright; // weighted sample towards darker pixels do { ix=random(0, img.width); iy=random(0, img.height); c = img.get((int)ix, (int)iy); bright = brightness(c); } while ((float)random (bright)>(float)thresh); fill(c); stroke(c); strokeWeight(random(2, 5)); x=ix*(float)imgw/(float)img.width; y=iy*(float)imgh/(float)img.height; line(10+x, 10+y, 10+x+random(-10, 10), 10+y+random(-10, 10)); } void draw() { //image(img,0,0,800,600); randstroke(); } void thresh(float theThresh) { thresh=theThresh; println("a slider event. setting brightness threshold to "+theThresh); }