Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import processing.serial.*;
  2.  
  3. Serial port;  // The serial port
  4. int R=255;
  5. int G=255;
  6. int B=255;
  7.  
  8. void setup() {
  9.   //   println(Serial.list());
  10.  port = new Serial(this, Serial.list()[0], 9600);
  11.   size(600, 400);//tamaño de la ventana
  12.   background(128); //color de fondo
  13.   frameRate(10);
  14. }
  15.  
  16. void draw() {
  17.  
  18.   port.write('R');  
  19.   port.write(R);
  20.   port.write('G');  
  21.   port.write(G);
  22.   port.write('B');  
  23.   port.write(B);
  24.  
  25.  
  26.   fill(R, G, B); //
  27.   rect(200, 010, 150, 150); // R
  28.  
  29.   //rectMode(CORNER); //modo en que se interpretarán los parámetros en rect()rect(10,10,120,8
  30.  
  31.   fill(0, 0, 0); // negro
  32.   triangle(100, 245, 125, 200, 150, 245); // R
  33.   fill(R, 0, 0);
  34.   if (mousePressed && ((mouseX>114)&&(mouseX<134)) && ((mouseY>220)&&(mouseY<240)) )
  35.   {  
  36.     if ( R >= 0  && R<=250)
  37.     {  
  38.       R= R+5;    
  39.       fill(R, 0, 0); // rojo
  40.     }
  41.   }
  42.  
  43.   if (mousePressed && ((mouseX>114)&&(mouseX<134)) && ((mouseY>300)&&(mouseY<320)) )
  44.   {
  45.     if ( R<= 255  && R>=5)
  46.     {  
  47.       R= R-5;    
  48.       fill(R, 0, 0); // rojo
  49.     }
  50.   }
  51.   rect(100, 250, 50, 50); // Rectangulo  R
  52.   fill(0, 0, 0); // negro
  53.   triangle(100, 305, 150, 305, 125, 350); // R
  54.  
  55.  
  56.   fill(0, 0, 0); // negro rrelleno triangulo  aumentar G
  57.   triangle(250, 245, 275, 200, 300, 245); // crea triangulo  aumentar G
  58.   fill(0, G, 0);
  59.   if (mousePressed && ((mouseX>264)&&(mouseX<284)) && ((mouseY>220)&&(mouseY<240)) )
  60.   {  
  61.     if ( G >= 0  && G<=250)
  62.     {  
  63.       G= G+5;    
  64.       fill(0, G, 0); // verde
  65.     }
  66.   }
  67.   if (mousePressed && ((mouseX>264)&&(mouseX<284)) && ((mouseY>300)&&(mouseY<320)) )
  68.   {
  69.     if (G>=5  && G<= 255  )
  70.     {  
  71.       G= G-5;    
  72.       fill(0, G, 0); // verde
  73.     }
  74.   }
  75.  
  76.   rect(250, 250, 50, 50); // G crear rectangulo
  77.   fill(0, 0, 0); // negro
  78.   triangle(250, 305, 300, 305, 275, 350); // G
  79.  
  80.   fill(0, 0, 0); // negro
  81.   triangle(400, 245, 425, 200, 450, 245); // B
  82.   fill(0, 0, B); // azul
  83.   if (mousePressed && ((mouseX>414)&&(mouseX<434)) && ((mouseY>220)&&(mouseY<240)) )
  84.   {  
  85.     if ( B >= 0  && B<=250)
  86.     {  
  87.       B= B+5;    
  88.       fill(0, 0, B); // AZUL
  89.     }
  90.   }
  91.   if (mousePressed && ((mouseX>414)&&(mouseX<434)) && ((mouseY>300)&&(mouseY<320)) )
  92.   {
  93.     if (B>=5  && B<= 255  )
  94.     {  
  95.       B= B-5;    
  96.       fill(0, 0, B); // AZUL
  97.     }
  98.   }
  99.  
  100.   rect(400, 250, 50, 50); // B
  101.   fill(0, 0, 0); // negro
  102.   triangle(400, 305, 450, 305, 425, 350); // B
  103.  
  104.   println(mouseX + ":" +mouseY+ ":"+ "R"+ R+":"+ "G"+G+":"+ "B:"+B);
  105. }