Está en la página 1de 2

Ejemplos condicionales 2

Ejemplo 1:

void setup ()
{
size (200,200);
frameRate (2);
}
void draw ()
{
background (255);
stroke (0);
line (width/2, 0, width/2,height/2);
line (0, height/2, width, height/2);
rectMode (CORNER);
fill (0);
if (mouseX < width/2 && mouseY < height/2)
{
fill (random (255), random (255), random (255));
rect (0, 0, width/2, height/2);
}
else if (mouseX > width/2 && mouseY < height/2)
{
fill (random (255), random (255), random (255));
rect (width/2, 0, width/2, height/2);
}
else if (mouseX < width/2 && mouseY > height/2)
{
fill (random (255), random (255), random (255));
rect (0, height/2, width/2, height/2);
}
else
{
fill (random (255), random (255), random (255));
rect (width/2, height/2, width/2, height/2);
}
}

Ejemplo 2:

boolean boton = false;


int blanco = 255;
int negro = 0;
void setup ()
{
size (200,200);
}
void draw ()
{
if (mouseX > 80 && mouseX < 120 && mouseY > 80 && mouseY < 120 &&
mousePressed)
//la condición se cumple cuando estamos dentro del cuadrado y presionamos el
mouse
{
boton = true;
}
1
else
{
boton = false;
}
if (boton)
// estamos clickando en el rectángulo
{
background (255,13,56);
stroke (negro);
}
else
// no estamos clickando dentro del rectángulo
{
background (43, 250, 78);
stroke (blanco);
}
//lo siguiente pinta un rectángulo gris en el centro de la pantalla
fill (175);
rect (80, 80, 40, 40);
}

También podría gustarte