// TrackerLeader03 // David Bollinger, January 2006 // http://www.davebollinger.com // for Processing 0015 Beta // // leader whose position is based on curves // tracker5 is a tracker4 that fills rect with transparent white // (helps erase display allowing for longer runs without clutter) class Leader2 extends Leader { float [] xs = new float[4]; float [] ys = new float[4]; float t, tinc; Leader2() { super(); config(); } Leader2(float _x, float _y) { super(_x,_y); config(); } float randx() { return random(width*0.3,width*0.7); } float randy() { return random(height*0.3,height*0.7); } void config() { for (int i=0; i<4; i++) { xs[i] = randx(); ys[i] = randy(); } t = 0.0; tinc = random(0.05,0.2); } void move(float dt) { x = curvePoint(xs[0], xs[1], xs[2], xs[3], t); y = curvePoint(ys[0], ys[1], ys[2], ys[3], t); t += tinc * dt; if (t >= 1.0) { t -= 1.0; for (int i=0; i<3; i++) { xs[i] = xs[i+1]; ys[i] = ys[i+1]; } xs[3] = randx(); ys[3] = randy(); } } } 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(); println("tinc = " + leader.tinc); } } void keyPressed() { if (key=='s') saveFrame("frame.tga"); }