/* We have generalized the control knobs to a class. In this class, the constructor requires 4 inputs: an image, and initial x, y coordinates, and an initial angle. The update() function computes a new angle based upon movement of the mouse in the y-direction. The draw() function rotates the image by the specified angle. This allows us to "turn" an image that looks like a knob. Of course this requires the image to be perfectly centered for things to look good. An alternative approach is to graphically draw an image of a knob. */ class Control { PImage img; float x; float y; float a; Control(PImage img0, float x0, float y0, float a0) { img = img0; x = x0; y = y0; a = a0; } void update() { a -= mouseY - pmouseY; a = constrain(a, -135, 135); } void draw() { pushMatrix(); translate(x, y); rotate(radians(a)); image(img, 0, 0); popMatrix(); } }