class Slider { float x, y; float target; float rad; boolean over; float xmin, xmax; float minval, valrange; Slider(float xpercent, float iy, float xmin, float xmax, float irad, float minval, float valrange) { this.minval = minval; this.valrange = valrange; this.xmin = xmin; this.xmax = xmax; x = (xmax-xmin)*xpercent + xmin; y = iy; rad = irad; over = false; } boolean inside(float mouseRad) { return overCircLast(x, y, rad + mouseRad); } boolean update(float mouseRad, float mXmove, float mYmove) { over = false; if (overCircLast(x, y, rad + mouseRad)) { over = true; if (mousePressed) { x += mXmove; if (x > xmax) x = xmax; if (x < xmin) x = xmin; //y += mYmove; } } return over; } float getDist(int i, int j) { float dx = x-(float)i; float dy = y-(float)j; return sqrt(dx*dx+dy*dy); } float getVal() { return minval + valrange*(x-xmin)/(xmax-xmin); } void display() { fill(255,50,50); ellipse(x,y,rad*2,rad*2); if (over) { fill(255); line(xmin,y,xmax,y); fill(255,255,0); ellipse(x,y,rad-1,rad-1); } stroke(255); text(getVal(),xmin,y-10); } } 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 - lastMx; float dy = y - lastMy; return (dx*dx + dy*dy < rad*rad); } int lock(int val, int minv, int maxv) { return min(max(val, minv), maxv); }