We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello everybody, I have a question about controlP5 in Python mode. I need to add a .jpg image to a group, and from this discussion (http://forum.processing.org/two/discussion/1841/controlp5-canvas-and-group/p1) I know I need the addDrawable() method. I can't figure out how to translate this short piece of Java code into Python:
import controlP5.*;
ControlP5 cp5;
PImage pic;
void setup() {
size(400, 400);
cp5 = new ControlP5(this);
pic = loadImage("bucky.jpg");
Group t = cp5.addGroup("group-test").setPosition(100, 100).setWidth(200);
cp5.addSlider("slider").setPosition(0, 10).moveTo(t);
t.addDrawable(new CDrawable() {
public void draw(PApplet p) {
p.pushMatrix();
p.image(pic,0,5,200,150);
p.popMatrix();
}
}
);
}
void draw() {
background(0);
}
I tried this, but I get a NullPointerException.
add_library('controlP5')
pic = loadImage("bucky.jpg")
def setup():
size(500,500)
cp5 = ControlP5(this)
g = cp5.addGroup('blah') \
.setPosition(50,50) \
.setWidth(250)
g.addDrawable(image(pic,0,0,250,150))
def draw():
background(0)
Does anybody have a clue? Thank you all.
Marco
Answers
Dunno Python yet but I'd daresay that cp5 is a local variable scoped to setup()! :-?
Moreover we shouldn't be messing w/ field g, since that's where the canvas' reference is stored! :-S
P.S.: Dunno whether Python Mode has this limitation but in Java Mode (and even in others)
sketchPath, width & height aren't initialized until setup() is called!
@GoToLoop thanks for your answer, I'll have some new attempts while waiting for some python expert to join the conversation ;)