// Tracker01 (point) // David Bollinger, January 2006 // http://www.davebollinger.com // for Processing 0015 Beta // // early tracker class dev // just draws a single point following mouse Tracker 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 Tracker(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; } } 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"); }