controlP5 rotate controller
in
Contributed Library Questions
•
2 years ago
I am trying to find a way to rotate a group of controller around a certain point according to the mouse position.
I tried searching in the Javadoc but havn't found a function that allows me to do that...
I tried with to figure out a solution but didn't really managed to achieve what i wanted.
here the code i wrote, hope someone could help me!
thanx
import controlP5.*;
ControlP5 controlP5;
ControlGroup l;
boolean over;
int x, y, size;
float angolo, myX, myY;
void setup() {
size(400,400);
frameRate(30);
x = 200;
y = 200;
controlP5 = new ControlP5(this);
l = controlP5.addGroup("myGroup",0,0);
controlP5.addBang("A-1",0,4,20,20).setGroup(l);
controlP5.addBang("A-2",30,4,20,20).setGroup(l);
l.setBackgroundColor(color(255,100));
l.setBackgroundHeight(150);
size = 40;
}
void draw() {
background(0);
noStroke();
fill(128);
pushMatrix();
translate(x, y);
rotate(angolo);
l.draw(this);
rect(60, -size/2, size, size);
popMatrix();
smooth();
stroke(255);
strokeWeight(10);
point(x, y);
}
void mouseDragged(){
myX = map (mouseX, 0, 400, -1, 1);
println("MYX : "+myX+" "+myY);
angolo = -acos(myX);
}
1