// control point class with some helpers for UI class Draggable { float x, y, z; float target; float rad; boolean over, overTop; Draggable(float ix, float iy, float itarget, float irad) { x = ix; y = iy; rad = irad; target = itarget; over = false; } boolean inside(float mouseRad) { return overCircLast(x, y, rad + mouseRad); } void update(float mouseRad, float mXmove, float mYmove) { over = false; overTop = false; if (overCircLast(x, y, rad + mouseRad)) { over = true; if (mousePressed) { if (mouseButton == RIGHT) { x += mXmove; y += mYmove; } } } if (overCircLast(x, y+z, rad + mouseRad)) { over = true; overTop = true; if (mousePressed) { if (mouseButton == LEFT) { z += mYmove; } } } } float getDist(int i, int j) { float dx = x-(float)i; float dy = y-(float)j; return sqrt(dx*dx+dy*dy); } void display() { strokeWeight(1); fill(valToCol(target,100,0)); ellipse(x,y,rad*2,rad*2); if (over) { fill(255,255,0); ellipse(x,y,rad-1,rad-1); } stroke(255,0,0); line(x,y,x,y+z); line(x-rad,y+z,x+rad,y+z); if (overTop) { fill(255,255,0); ellipse(x,y+z,rad-1,rad-1); } } } color valToCol(float val, float upscale, float eps) { if (val > eps) { int cc = (int)(val * upscale); cc += 150; cc = lock(cc,150,255); return color(0,cc,0); } else if (val < -eps) { int cc = (int)(-val * upscale); cc += 150; cc = lock(cc,150,255); return color(cc,0,0); } else { return color(255,255,0); } } boolean overCirc(float x, float y, float rad) { float dx = x - mouseX; float dy = y - mouseY; return (dx*dx + dy*dy < rad*rad); } boolean overCircLast(float x, float y, float rad) { float dx = x - pmouseX; float dy = y - pmouseY; return (dx*dx + dy*dy < rad*rad); } int lock(int val, int minv, int maxv) { return min(max(val, minv), maxv); }