Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import controlP5.*;
- ControlP5 cp5;
- Knob myKnobA;
- Knob myKnobB;
- int ncosas = 4;
- float sumangle = (2*PI)/ncosas;
- float angle = HALF_PI + PI + sumangle;
- int radius = 100;
- int counter = 1;
- int sumar = 25;
- int tablade = 1;
- int prueba = 30;
- void setup(){
- size(400,400);
- background(255);
- textAlign(CENTER,CENTER);
- fill(0);
- stroke(0);
- textSize(7);
- cp5 = new ControlP5(this);
- myKnobA = cp5.addKnob("Servo")
- .setRange(1,120)
- .setValue(1)
- .setPosition(20,90)
- .setRadius(30)
- .setDragDirection(Knob.HORIZONTAL)
- .setCaptionLabel("N")
- .setColorCaptionLabel(0)
- ;
- myKnobB = cp5.addKnob("TablaD")
- .setRange(1,20)
- .setValue(1)
- .setPosition(20,220)
- .setRadius(30)
- .setDragDirection(Knob.HORIZONTAL)
- .setCaptionLabel("Tabla de")
- .setColorCaptionLabel(0)
- ;
- //translate(height/2,width/2);
- //line(0,0,radius*sin(radians(prueba)),radius*cos(radians(prueba)));
- }
- void draw(){
- if(counter <= ncosas){
- dibujarTabla();
- }
- }
- void Servo(int theValue){
- background(255);
- counter = 1;
- ncosas = theValue;
- sumangle = (2*PI)/ncosas;
- angle = HALF_PI + PI + sumangle;
- }
- void TablaD(int theValue){
- background(255);
- counter = 1;
- tablade = theValue;
- angle = HALF_PI + PI + sumangle;
- }
- void dibujarTabla(){
- pushMatrix();
- translate(230,height/2);
- circle(radius*sin(angle),radius*cos(angle),2);
- //if(counter*tablade<=ncosas){
- line(radius*sin(angle),radius*cos(angle),radius*sin((counter*tablade*sumangle)+(angle-counter*sumangle)),radius*cos((counter*tablade*sumangle)+(angle-counter*sumangle)));
- //}
- println(counter*tablade + " -> " + counter*tablade*degrees(sumangle));
- text(counter,(radius+sumar)*sin(angle),(radius+sumar)*cos(angle));
- angle += sumangle;
- counter++;
- popMatrix();
- }
- void keyPressed(){
- if (key == 'D' || key == 'd'){
- Servo(int(myKnobA.getValue())+1);
- myKnobA.setValue(int(myKnobA.getValue())+1);
- }
- if (key == 'A' || key == 'a'){
- Servo(int(myKnobA.getValue())-1);
- myKnobA.setValue(int(myKnobA.getValue())-1);
- }
- if (key == 'W' || key == 'w'){
- TablaD(int(myKnobB.getValue())+1);
- myKnobB.setValue(int(myKnobB.getValue())+1);
- }
- if (key == 'S' || key == 's'){
- TablaD(int(myKnobB.getValue())-1);
- myKnobB.setValue(int(myKnobB.getValue())-1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement