Skip to content

Instantly share code, notes, and snippets.

@eskimoblood
Last active August 29, 2015 13:58
Show Gist options
  • Save eskimoblood/10414654 to your computer and use it in GitHub Desktop.
Save eskimoblood/10414654 to your computer and use it in GitHub Desktop.
Nice way to have your private variables editable in a external window.
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);
}
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);
}
}
@cacheflowe
Copy link

This is awesome! Thanks for sharing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment