import processing.serial.*;
Serial port; // The serial port
int R=255;
int G=255;
int B=255;
void setup() {
// println(Serial.list());
port = new Serial(this, Serial.list()[0], 9600);
size(600, 400);//tamaño de la ventana
background(128); //color de fondo
frameRate(10);
}
void draw() {
port.write('R');
port.write(R);
port.write('G');
port.write(G);
port.write('B');
port.write(B);
fill(R, G, B); //
rect(200, 010, 150, 150); // R
//rectMode(CORNER); //modo en que se interpretarán los parámetros en rect()rect(10,10,120,8
fill(0, 0, 0); // negro
triangle(100, 245, 125, 200, 150, 245); // R
fill(R, 0, 0);
if (mousePressed && ((mouseX>114)&&(mouseX<134)) && ((mouseY>220)&&(mouseY<240)) )
{
if ( R >= 0 && R<=250)
{
R= R+5;
fill(R, 0, 0); // rojo
}
}
if (mousePressed && ((mouseX>114)&&(mouseX<134)) && ((mouseY>300)&&(mouseY<320)) )
{
if ( R<= 255 && R>=5)
{
R= R-5;
fill(R, 0, 0); // rojo
}
}
rect(100, 250, 50, 50); // Rectangulo R
fill(0, 0, 0); // negro
triangle(100, 305, 150, 305, 125, 350); // R
fill(0, 0, 0); // negro rrelleno triangulo aumentar G
triangle(250, 245, 275, 200, 300, 245); // crea triangulo aumentar G
fill(0, G, 0);
if (mousePressed && ((mouseX>264)&&(mouseX<284)) && ((mouseY>220)&&(mouseY<240)) )
{
if ( G >= 0 && G<=250)
{
G= G+5;
fill(0, G, 0); // verde
}
}
if (mousePressed && ((mouseX>264)&&(mouseX<284)) && ((mouseY>300)&&(mouseY<320)) )
{
if (G>=5 && G<= 255 )
{
G= G-5;
fill(0, G, 0); // verde
}
}
rect(250, 250, 50, 50); // G crear rectangulo
fill(0, 0, 0); // negro
triangle(250, 305, 300, 305, 275, 350); // G
fill(0, 0, 0); // negro
triangle(400, 245, 425, 200, 450, 245); // B
fill(0, 0, B); // azul
if (mousePressed && ((mouseX>414)&&(mouseX<434)) && ((mouseY>220)&&(mouseY<240)) )
{
if ( B >= 0 && B<=250)
{
B= B+5;
fill(0, 0, B); // AZUL
}
}
if (mousePressed && ((mouseX>414)&&(mouseX<434)) && ((mouseY>300)&&(mouseY<320)) )
{
if (B>=5 && B<= 255 )
{
B= B-5;
fill(0, 0, B); // AZUL
}
}
rect(400, 250, 50, 50); // B
fill(0, 0, 0); // negro
triangle(400, 305, 450, 305, 425, 350); // B
println(mouseX + ":" +mouseY+ ":"+ "R"+ R+":"+ "G"+G+":"+ "B:"+B);
}