Last active
August 29, 2015 13:58
-
-
Save eskimoblood/10414654 to your computer and use it in GitHub Desktop.
Nice way to have your private variables editable in a external window.
This file contains hidden or 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 control.ControlFrame; | |
import processing.core.PApplet; | |
public class BackgroundColor { | |
private final PApplet p; | |
@ControlElement(properties = {"min=0", "max=255"}, x = 10, y = 10) | |
private float red = 0; | |
@ControlElement(properties = {"min=0", "max=255"}, x = 10, y = 10) | |
private float green = 0; | |
@ControlElement(properties = {"min=0", "max=255"}, x = 10, y = 10) | |
private float blue = 0; | |
public BackgroundColor(PApplet p) { | |
this.p = p; | |
new ControlFrame(this, 200, 200); | |
} | |
public void update() { | |
p.background(red, green, blue); | |
} | |
This file contains hidden or 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
package control; | |
import controlP5.ControlP5; | |
import processing.core.PApplet; | |
import java.awt.*; | |
public class ControlFrame extends PApplet { | |
int w; | |
int h; | |
public void setup() { | |
size(w, h); | |
frameRate(25); | |
} | |
public void draw() { | |
background(0); | |
} | |
public ControlFrame(Object parent, int theWidth, int theHeight) { | |
String name = parent.getClass().getSimpleName(); | |
w = theWidth; | |
h = theHeight; | |
createFrame(name); | |
createControlP5(parent, name); | |
} | |
private void createFrame(String name) { | |
Frame f = new Frame(name); | |
f.add(this); | |
this.init(); | |
f.setTitle(name); | |
f.setSize(w, h); | |
f.setLocation(100, 100); | |
f.setResizable(false); | |
f.setVisible(true); | |
} | |
private void createControlP5(Object parent, String name) { | |
ControlP5 cp5 = new ControlP5(this); | |
cp5.addControllersFor(name, parent); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is awesome! Thanks for sharing.