Advertisement
ahorsewithnoname

Módulo 1

May 9th, 2021
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.56 KB | None | 0 0
  1. import controlP5.*;
  2.  
  3. ControlP5 cp5;
  4. Knob myKnobA;
  5. Knob myKnobB;
  6.  
  7. int ncosas = 4;
  8. float sumangle = (2*PI)/ncosas;
  9. float angle = HALF_PI + PI + sumangle;
  10. int radius = 100;
  11. int counter = 1;
  12. int sumar = 25;
  13. int tablade = 1;
  14. int prueba = 30;
  15.  
  16. void setup(){
  17.   size(400,400);
  18.   background(255);
  19.   textAlign(CENTER,CENTER);
  20.   fill(0);
  21.   stroke(0);
  22.   textSize(7);
  23.   cp5 = new ControlP5(this);
  24.   myKnobA = cp5.addKnob("Servo")
  25.                .setRange(1,120)
  26.                .setValue(1)
  27.                .setPosition(20,90)
  28.                .setRadius(30)
  29.                .setDragDirection(Knob.HORIZONTAL)
  30.                .setCaptionLabel("N")
  31.                .setColorCaptionLabel(0)
  32.                ;
  33.            
  34.   myKnobB = cp5.addKnob("TablaD")
  35.                .setRange(1,20)
  36.                .setValue(1)
  37.                .setPosition(20,220)
  38.                .setRadius(30)
  39.                .setDragDirection(Knob.HORIZONTAL)
  40.                .setCaptionLabel("Tabla de")
  41.                .setColorCaptionLabel(0)
  42.                ;
  43.   //translate(height/2,width/2);
  44.  
  45.  
  46.   //line(0,0,radius*sin(radians(prueba)),radius*cos(radians(prueba)));
  47.  
  48.  
  49.  
  50. }
  51.  
  52. void draw(){
  53.   if(counter <= ncosas){
  54.     dibujarTabla();
  55.   }
  56. }
  57.  
  58. void Servo(int theValue){
  59.   background(255);
  60.   counter = 1;
  61.   ncosas = theValue;
  62.   sumangle = (2*PI)/ncosas;
  63.   angle = HALF_PI + PI + sumangle;
  64. }
  65.  
  66. void TablaD(int theValue){
  67.   background(255);
  68.   counter = 1;
  69.   tablade = theValue;
  70.   angle = HALF_PI + PI + sumangle;
  71. }
  72.  
  73.  
  74. void dibujarTabla(){
  75.   pushMatrix();
  76.   translate(230,height/2);
  77.   circle(radius*sin(angle),radius*cos(angle),2);
  78.   //if(counter*tablade<=ncosas){
  79.   line(radius*sin(angle),radius*cos(angle),radius*sin((counter*tablade*sumangle)+(angle-counter*sumangle)),radius*cos((counter*tablade*sumangle)+(angle-counter*sumangle)));
  80.   //}
  81.   println(counter*tablade + " -> " + counter*tablade*degrees(sumangle));
  82.   text(counter,(radius+sumar)*sin(angle),(radius+sumar)*cos(angle));
  83.   angle += sumangle;
  84.   counter++;
  85.   popMatrix();
  86. }
  87.  
  88. void keyPressed(){
  89.   if (key == 'D' || key == 'd'){
  90.       Servo(int(myKnobA.getValue())+1);
  91.       myKnobA.setValue(int(myKnobA.getValue())+1);
  92.   }
  93.   if (key == 'A' || key == 'a'){
  94.       Servo(int(myKnobA.getValue())-1);
  95.       myKnobA.setValue(int(myKnobA.getValue())-1);
  96.   }
  97.   if (key == 'W' || key == 'w'){
  98.       TablaD(int(myKnobB.getValue())+1);
  99.       myKnobB.setValue(int(myKnobB.getValue())+1);
  100.   }
  101.   if (key == 'S' || key == 's'){
  102.       TablaD(int(myKnobB.getValue())-1);
  103.       myKnobB.setValue(int(myKnobB.getValue())-1);
  104.   }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement