Control p5 Matrix
in
Contributed Library Questions
•
4 months ago
Hi there. I am wondering if anyone knows how to change the parameters for a control p5 object (for example the interval in the matrix example), in live performance. (i.e. when the sketch is running).
My example shows the interval parameter as
int tempo and i am trying to say, when the mouse is pressed, tempo = 300.
any help on this would be greatly appreciated. Thanks :)
//code
import controlP5.*;
ControlP5 cp5;
Dong[][] d;
int nx = 10;
int ny = 10;
int tempo;
void setup() {
size(700, 400);
cp5 = new ControlP5(this);
cp5.printPublicMethodsFor(Matrix.class);
cp5.addMatrix("myMatrix")
.setPosition(50, 100)
.setSize(200, 200)
.setGrid(nx, ny)
.setGap(10, 1)
.setInterval(tempo)
.setMode(ControlP5.MULTIPLES)
.setColorBackground(color(120))
.setBackground(color(40))
;
cp5.getController("myMatrix").getCaptionLabel().alignX(CENTER);
// use setMode to change the cell-activation which by
// default is ControlP5.SINGLE_ROW, 1 active cell per row,
// but can be changed to ControlP5.SINGLE_COLUMN or
// ControlP5.MULTIPLES
d = new Dong[nx][ny];
for (int x = 0;x<nx;x++) {
for (int y = 0;y<ny;y++) {
d[x][y] = new Dong();
}
}
noStroke();
smooth();
}
void draw() {
background(0);
fill(255, 100);
pushMatrix();
translate(width/2 + 150, height/2);
rotate(frameCount*0.001);
for (int x = 0;x<nx;x++) {
for (int y = 0;y<ny;y++) {
d[x][y].display();
}
}
popMatrix();
}
void myMatrix(int theX, int theY) {
println("got it: "+theX+", "+theY);
d[theX][theY].update();
}
void mousePressed() {
if(mousePressed == true) {
tempo = 300; }
else { tempo = 2000;
}
}
void controlEvent(ControlEvent theEvent) {
}
class Dong {
float x, y;
float s0, s1;
Dong() {
float f= random(-PI, PI);
x = cos(f)*random(100, 150);
y = sin(f)*random(100, 150);
s0 = random(2, 10);
}
void display() {
s1 += (s0-s1)*0.1;
ellipse(x, y, s1, s1);
}
void update() {
s1 = 50;
}
}
1