// Tracker04 (squares) // David Bollinger, January 2006 // http://www.davebollinger.com // for Processing 0015 Beta // // early tracker class dev // draws a rectangle perpendicular to direction of travel whose width // is scaled proportionately to distance travelled class Tracker4 extends Tracker { Tracker4(int _x, int _y) { super(_x, _y); } void draw() { stroke(clr); noFill(); 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(); } } Tracker4 tracker; HScrollbar hsr; HScrollbar hsf; boolean isDrawing = false; float timeslice = 0.1; boolean bGotMouse = false; color bgcolor = #ffffff; color fgcolor = color(8,32,128,32); void setup() { size(480,480,P3D); background(bgcolor); tracker = new Tracker4(width/2, height/2); tracker.setColor(fgcolor); 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()); boolean localGotMouse = bGotMouse; if (hsr.over || hsf.over) localGotMouse = false; if (localGotMouse) { float targetx = (float)(mouseX); float targety = (float)(mouseY); tracker.setTarget(targetx, targety); float elapsed = 0.0; while (elapsed < 1.0) { tracker.move(timeslice ); if (isDrawing) tracker.draw(); elapsed += timeslice; } } rectMode(CORNER); hsr.draw(); hsf.draw(); } void mousePressed() { bGotMouse = true; if (mouseButton == LEFT) { isDrawing = true; } else if (mouseButton == RIGHT) { background(bgcolor); } } void mouseReleased() { if (mouseButton == LEFT) { isDrawing = false; } } void keyPressed() { if (key=='s') saveFrame("frame.tga"); }