// TrackerLeader02 // David Bollinger, January 2006 // http://www.davebollinger.com // for Processing 0015 Beta // // leader whose position is based on sine waves // tracker5 is a tracker4 that fills rect with transparent white // (helps erase display allowing for longer runs without clutter) class Leader2 extends Leader { float xtheta, xtinc, xtincinc; float ytheta, ytinc, ytincinc; Leader2() { super(); config(); } Leader2(float _x, float _y) { super(_x,_y); config(); } void config() { xtheta = random(-PI,PI); ytheta = random(-PI,PI); xtinc = random(-1.0,1.0); ytinc = random(-1.0,1.0); xtincinc = random(0.003, 0.01); ytincinc = random(0.003, 0.01); } void move(float dt) { x = (width*0.5) + (width*0.25) * cos(xtheta); y = (height*0.5) + (height*0.25) * sin(ytheta); xtheta += xtinc * dt; ytheta += ytinc * dt; xtinc += xtincinc * dt; if ((xtinc < -1) || (xtinc > 1)) xtincinc = -xtincinc; ytinc += ytincinc * dt; if ((ytinc < -1) || (ytinc > 1)) ytincinc = -ytincinc; } } class Tracker5 extends Tracker { Tracker5(int _x, int _y) { super(_x, _y); } void draw() { stroke(clr); fill(color(255,255,255,32)); rectMode(CENTER); float theta = tracker.getAngle(); float dx = tracker.x - tracker.lastx; float dy = tracker.y - tracker.lasty; float rad = dx*dx + dy*dy; //float rad = dist(tracker.lastx, tracker.lasty, tracker.x, tracker.y); pushMatrix(); translate(tracker.x, tracker.y); rotate(theta); rect(0, 0, rad, rad); popMatrix(); } } Tracker5 tracker; Leader2 leader; HScrollbar hsr; HScrollbar hsf; float timeslice = 0.1; color bgcolor = #ffffff; color fgcolor = color(8,32,128,32); void setup() { size(480,480,P3D); background(bgcolor); tracker = new Tracker5(width/2, height/2); tracker.setColor(fgcolor); leader = new Leader2(width/2, height/2); PFont font = loadFont("small-6.vlw"); hsr = new HScrollbar(10, height-20, 100, 8, 5, "RATE", font); hsr.setRange(0.01,0.1); hsr.setValue(0.05); hsf = new HScrollbar(10, height-8, 100, 8, 5, "FRICTION", font); hsf.setRange(0.01,0.1); hsf.setValue(0.05); // in general (friction >= rate) is a "better" mouse follower } void draw() { hsr.update(); hsf.update(); tracker.setPhysics(hsr.getValue(), hsf.getValue()); leader.move(1.0); tracker.setTarget(leader.x, leader.y); float elapsed = 0.0; while (elapsed < 1.0) { tracker.move(timeslice ); tracker.draw(); elapsed += timeslice; } rectMode(CORNER); hsr.draw(); hsf.draw(); } void mousePressed() { if (mouseButton == RIGHT) { background(bgcolor); leader.config(); } } void keyPressed() { if (key=='s') saveFrame("frame.tga"); }