Aparecen nuevos colores a medida que escriben con el teclado

int rectWidth;

void setup() {
 size(640, 640);
 noStroke();
 background(#06A5BA);
 rectWidth = width/4;
}
void draw() {
 // keep draw() here to continue looping while waiting for keys
}
void keyPressed() {
 int keyIndex = -1;
 if (key >= 'A' && key <= 'Z') {
 keyIndex = key - 'A';
 } else if (key >= 'a' && key <= 'z') {
 keyIndex = key - 'a';
 }
 if (keyIndex == -1) {
 // If it's not a letter key, clear the screen
 background(#BA06B6);
 } else {
 // It's a letter key, fill a rectangle
 fill(millis() % 255);
 float x = map(keyIndex, 0, 25, 0, width - rectWidth);
 rect(x, 0, rectWidth, height);
 }
 if (keyIndex == -1) {
 // If it's not a letter key, clear the screen
 background(#E2E200);
 } else {
 // It's a letter key, fill a rectangle
 fill(millis() % 255);
 float x = map(keyIndex, 0, 25, 0, width - rectWidth);
 rect(x, 0, rectWidth, height);
 }
}

Deja una respuesta

Tu dirección de correo electrónico no será publicada.

You may also like