|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectcontrolP5.ControlBehavior
public abstract class ControlBehavior
control behavior is an abstract class and must be extended, update() must be implemented in your custom control behavior. how to use ControlBehavior please see the ControlP5behavior example in the examples folder.
/** * ControlP5behavior
* ControlBehavior is an abstract class that can be extended using your * custom control behaviors. What is a control behavior? Control Behaviors * allow you to automate and dynamically change the state or value of a * controller. One behavior per controller is currently supported. i case you * need to use more that one bahavior, the implementation has to happen * on your side - inside your control behavior.
* by Andreas Schlegel 2010
* */ import controlP5.*; ControlP5 controlP5; int myColorBackground = color(0,0,0); public int sliderValue = 100; void setup() { size(400,400); frameRate(30); controlP5 = new ControlP5(this); controlP5.addSlider("sliderValue",0,255,128,100,50 + height/2,40,100); controlP5.addSlider("slider",100,255,128,100,50,100,40); controlP5.addBang("bang",40,50 + height/2,40,40); // add a custom ControlBehavior to controller bang, // class TimerEvent is included in this sketch at the bottom // and extends abstract class ControlBehavior. controlP5.controller("bang").setBehavior(new TimedEvent()); // use an anonymous class of type ControlBehavior. controlP5.controller("slider").setBehavior(new ControlBehavior() { float a = 0; public void update() { setValue(sin(a += 0.1) * 50 + 150); } }); } void draw() { background(myColorBackground); fill(sliderValue); rect(0,0,width,height/2); } void slider(float theColor) { myColorBackground = color(theColor); println("# a slider event. setting background to "+theColor); } public void bang() { println("# an event received from controller bang."); // a bang will set the value of controller sliderValue // to a random number between 0 and 255. controlP5.controller("sliderValue").setValue(random(0,255)); } // custom ControlBehavior class TimedEvent extends ControlBehavior { long myTime; int interval = 200; public TimedEvent() { reset(); } void reset() { myTime = millis() + interval; } public void update() { if(millis()>myTime) { setValue(1); reset(); } } }
Constructor Summary | |
---|---|
ControlBehavior()
|
Method Summary | |
---|---|
Controller |
controller()
returns the controller this behavior is connected to. |
boolean |
isActive()
check if the behavior is active or not. |
void |
setActive(boolean theFlag)
(de)activate the behavior. |
void |
setValue(float theValue)
set the value of the controller. |
abstract void |
update()
when extending ControlBehavior, update() has to be overwritten. |
float |
value()
get the value of the controller this behavior is connected to. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ControlBehavior()
Method Detail |
---|
public Controller controller()
public void setValue(float theValue)
theValue
- floatpublic float value()
public abstract void update()
public void setActive(boolean theFlag)
theFlag
- booleanpublic boolean isActive()
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |