Created
April 28, 2011 13:31
-
-
Save medecau/946348 to your computer and use it in GitHub Desktop.
Processing controlP5 round button
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import controlP5.*; | |
ControlPad cp; | |
ControlP5 controlP5; | |
void setup() { | |
size(400, 400); | |
frameRate(30); | |
smooth(); | |
controlP5 = new ControlP5(this); | |
cp = new ControlPad(controlP5, "DIY", 60, 40, 100, 200); | |
controlP5.register(cp); | |
} | |
void draw() { | |
background(0); | |
} | |
void controlEvent(ControlEvent theEvent) { | |
println(theEvent.arrayValue()); | |
} | |
class ControlPad extends Controller { | |
ControlPad(ControlP5 theControlP5, String theName, int theX, int theY, int theWidth, int theHeight) { | |
super(theControlP5, (Tab)(theControlP5.getTab("default")), theName, theX, theY, theWidth, theHeight); | |
} | |
public void updateInternalEvents(PApplet theApplet) { | |
// get your actions here | |
} | |
protected boolean inside() { | |
float centerX = position.x+width/2; | |
float centerY = position.y+height/2; | |
float majorRadius, minorRadius, focalDistance, fp1x, fp1y, fp2x, fp2y; | |
if (width>height) { | |
majorRadius=width/2; | |
minorRadius=height/2; | |
focalDistance=sqrt(pow(majorRadius, 2)-pow(minorRadius, 2)); | |
fp1x=centerX-focalDistance; | |
fp2x=centerX+focalDistance; | |
fp1y=centerY; | |
fp2y=centerY; | |
} | |
else { | |
majorRadius=height/2; | |
minorRadius=width/2; | |
focalDistance=sqrt(pow(majorRadius, 2)-pow(minorRadius, 2)); | |
fp1y=centerY-focalDistance; | |
fp2y=centerY+focalDistance; | |
fp1x=centerX; | |
fp2x=centerX; | |
} | |
float fp1Distance=dist(fp1x, fp1y, mouseX, mouseY); | |
float fp2Distance=dist(fp2x, fp2y, mouseX, mouseY); | |
return (fp1Distance+fp2Distance<2*majorRadius); | |
} | |
// overwrite the draw method for the controller's visual representation. | |
public void draw(PApplet theApplet) { | |
// use pushMatrix and popMatrix when drawing | |
// the controller. | |
theApplet.pushMatrix(); | |
theApplet.translate(position().x(), position().y()); | |
// draw the background of the controller. | |
if (getIsInside()) { | |
theApplet.fill(150); | |
} | |
else { | |
theApplet.fill(100); | |
} | |
ellipse(0, 0, width, height); | |
theApplet.popMatrix(); | |
} | |
void setValue(float v){} | |
public void addToXMLElement(ControlP5XMLElement theElement) { | |
} | |
} | |
void drawCrossAir(float x, float y) { | |
stroke(255, 0, 0); | |
line(x-5, y-5, x+5, y+5); | |
line(x-5, y+5, x+5, y-5); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment