Advertisement
Guest User

Untitled

a guest
May 29th, 2015
1,596
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.28 KB | None | 0 0
  1. // Se utiliza las librerias ControlP5 y Serial del Processing
  2. import controlP5.*;
  3. import processing.serial.*;
  4.  
  5. // Se define la variable cP5 del tipo ControlP5
  6. ControlP5 cP5;
  7.  
  8. // Se le da nombres a los tres Knob y al Serial
  9. Knob PerRed;
  10. Knob PerGre;
  11. Knob PerBlu;
  12. Serial serial;
  13.  
  14. // Se necesitan inicializar el valor de los colores RGB
  15. // en este caso lo hacemos en 128
  16. int Red = 128;
  17. int Gre = 128;
  18. int Blu = 128;
  19.  
  20. // Configuración inicial
  21. void setup() {
  22.   size(700, 550);  //Tamaño de la ventana
  23.  
  24.   cP5 = new ControlP5(this);  //Crea el objeto ControlP5
  25.  
  26.   // Crea el Knob del color Rojo
  27.   PerRed = cP5.addKnob("R")
  28.     .setRange(0, 128)
  29.       .setValue(86)
  30.         .setPosition(100, 280)
  31.           .setRadius(100)
  32.             .setNumberOfTickMarks(20)
  33.               .setTickMarkLength(8)
  34.                 .setLabelVisible(false)
  35.                   .setColorForeground(color(255))
  36.                     .setColorBackground(color(0))
  37.                       .setColorActive(color(255, 0, 0))
  38.                         .setDragDirection(Knob.HORIZONTAL)
  39.                           ;
  40.   // Crea el Knob del color Verde
  41.   PerGre = cP5.addKnob("G")
  42.     .setRange(0, 128)
  43.       .setValue(128)
  44.         .setPosition(250, 110)
  45.           .setRadius(100)
  46.             .setNumberOfTickMarks(20)
  47.               .setTickMarkLength(8)
  48.                 .setLabelVisible(false)
  49.                   .setColorForeground(color(255))
  50.                     .setColorBackground(color(0))
  51.                       .setColorActive(color(0, 255, 0))
  52.                         .setDragDirection(Knob.HORIZONTAL)
  53.                           ;
  54.   // Crea el Knob del color Azul
  55.   PerBlu = cP5.addKnob("B")
  56.     .setRange(0, 128)
  57.       .setValue(170)
  58.         .setPosition(400, 280)
  59.           .setRadius(100)
  60.             .setNumberOfTickMarks(20)
  61.               .setTickMarkLength(8)
  62.                 .setLabelVisible(false)
  63.                   .setColorForeground(color(255))
  64.                     .setColorBackground(color(0))
  65.                       .setColorActive(color(0, 0, 255))
  66.                         .setDragDirection(Knob.HORIZONTAL)
  67.                           ;
  68.  
  69.   String puerto = Serial.list()[0];
  70.   serial = new Serial(this, puerto, 9600);
  71. }
  72.  
  73. // Se dibuja cada frame
  74. void draw() {
  75.   background(0xFF444444);  //Color Gris del fondo
  76.  
  77.   fill(Red, Gre, Blu);
  78.   rect(50, 90, 600, 415);
  79.   fill(0xFF444444);
  80.   rect(55, 95, 590, 405);
  81.   fill(Red, 0, 0);
  82.   ellipse(200, 380, 220, 220);
  83.   fill(0, Gre, 0);
  84.   ellipse(350, 210, 220, 220);
  85.   fill(0, 0, Blu);
  86.   ellipse(500, 380, 220, 220);
  87.   fill(Red, Gre, Blu);
  88.   text("ROJO", 60, 490);
  89.   fill(0, Gre, 0);
  90.   textSize(30);
  91.   text("VERDE", 445, 135);
  92.   fill(0, 0, Blu);
  93.   textSize(30);
  94.   text("AZUL", 350, 490);
  95.   fill(255);
  96.   textSize(25);
  97.   text("FABIO NELSON VALENCIA", 190, 540);
  98. }
  99.  
  100. // Como se va a actuar cuando ocurra un evento con los Knobs
  101. void controlEvent(ControlEvent evento) {
  102.   String nombre = evento.getController().getName();
  103.   int valor = int(evento.getController().getValue());
  104.   serial.write(nombre + valor);
  105.  
  106.   // Guarda el valor en la variable para cada color,
  107.   // cuando se usa cada Knob
  108.   if (nombre == "R") {
  109.     Red = valor;
  110.   }
  111.   if (nombre == "G") {
  112.     Gre = valor;
  113.   }
  114.   if (nombre == "B") {
  115.     Blu = valor;
  116.   }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement