ControlP5
controlP5 is a GUI library written by Andreas Schlegel for processing. It can be used in authoring, application, and applet mode. It allows you to easily add controllers such as Sliders, Buttons, Toggles, Knobs, Textfields, RadioButtons, Checkboxes amongst others to your processing sketches. They can be arranged in separate control windows, and can be organized in tabs or groups.
ControlP5 Features
Automatic controller-event detection
The library provides a range of controllers that allow you to easily change and adjust values while your sketches are running. Each controller is identified by a unique name assigned when you create the controller. ControlP5 locates variables and functions inside your sketch and will link controllers to matching variables or functions automatically
/**
* ControlP5 Toggle by andreas schlegel, 2009
modified by Lizabeth Arum, 2012
*/
import controlP5.*;
ControlP5 controlP5;
int myColorBackground = color(255);
boolean cubeColor= true;
void setup() {
size(200, 200, P3D );
smooth();
controlP5 = new ControlP5(this);
controlP5.begin(10, 10);
controlP5.addToggle("toggle", false, 10, 10, 20, 20);
controlP5.addToggle("cubeColor", true, 40, 10, 20, 20);
controlP5.end();
}
void draw() {
background(myColorBackground);
if (cubeColor) {
fill(0, 255, 0);
}
else {
fill(255, 0, 0);
}
noStroke();
lights();
pushMatrix();
translate(width/2, height/2, 0);
rotateY(map(mouseX, 0, width, -PI, PI));
rotateX(map(mouseY, 0, height, PI, -PI));
box(80);
popMatrix();
controlP5.draw();
}
void toggle(boolean theFlag) {
if (theFlag==true) {
myColorBackground = color(100);
}
else {
myColorBackground = color(255);
}
println("a toggle event.");
}
ControlEvents:
/**
* ControlP5 ControlEvent by andreas schlegel, 2009
* modified by Lizabeth Arum, 2012
*/
import controlP5.*;
ControlP5 controlP5;
public int redVal = 200;
public int greenVal = 200;
public int blueVal = 200;
public int myColorBackground = 0;
public int dim = 50;
void setup() {
size(300, 200, P3D);
frameRate(25);
controlP5 = new ControlP5(this);
Numberbox r=controlP5.addNumberbox("red", redVal, 10, 10, 60, 14);
Numberbox g=controlP5.addNumberbox("green", greenVal, 10, 40, 60, 14);
Numberbox b=controlP5.addNumberbox("blue", blueVal, 10, 70, 60, 14);
Numberbox n2 = controlP5.addNumberbox("bg", myColorBackground, 80, 10, 60, 14);
Numberbox n3 = controlP5.addNumberbox("size", dim, 150, 10, 60, 14);
r.setColorForeground(color( 255, 0, 0));
r.setMin(0);
r.setMax(255);
r.setId(1);
g.setColorForeground(color( 0, 255, 0));
g.setMin(0);
g.setMax(255);
g.setId(2);
b.setColorForeground(color( 0, 0, 255));
b.setMin(0);
b.setMax(255);
b.setId(3);
n2.setMin(0);
n2.setMax(255);
n2.setId(4);
n3.setMin(5);
n3.setMax(100);
n3.setId(5);
}
void draw() {
background(myColorBackground);
fill(redVal, greenVal, blueVal);
noStroke();
lights();
pushMatrix();
translate(width/2, height/2, -20);
rotateY( -PI/3);
rotateX( PI/3);
box(dim);
popMatrix();
controlP5.draw();
}
void controlEvent(ControlEvent theEvent) {
println("got a control event from controller with id "+theEvent.controller().id()+" "+(int)theEvent.controller().value());
switch(theEvent.controller().id()) {
case(1):
redVal = (int)(theEvent.controller().value());
break;
case(2):
greenVal = (int)(theEvent.controller().value());
break;
case(3):
blueVal = (int)(theEvent.controller().value());
break;
case(4):
myColorBackground = (int)(theEvent.controller().value());
break;
case(5):
dim = (int)(theEvent.controller().value());
break;
}
}