Assignment 2

PURPOSE:

Activating elements on screen based on keyboard inputs.
Four keys were mapped to four squares on the screen that would blink in a specific colour based on the character keyed in (R-Red,B-Blue,Y-Yellow,G-Green)

PROGRAM:

int a=75;//side of squares
int d=50;//depth of squares
int x1=20;
int x2=115;
int x3=210;
int x4=305;
void setup()
{
size(400,300);
background(255);
rect(x1,d,a,a);
rect(x2,d,a,a);
rect(x3,d,a,a);
rect(x4,d,a,a);
}

void draw()
{

}

void keyReleased() 
{
if(key=='y'||key=='Y')
{
fill(255,255,0);
rect(x1,d,a,a);
fill(255);
rect(x2,d,a,a);
rect(x3,d,a,a);
rect(x4,d,a,a);
}
else
{
if(key=='g'||key=='G')
{
fill(0,255,0);
rect(x2,d,a,a);
fill(255);
rect(x1,d,a,a);
rect(x3,d,a,a);
rect(x4,d,a,a);
}
else{
if(key=='b'||key=='B')
{
fill(0,0,255);
rect(x3,d,a,a);
fill(255);
rect(x1,d,a,a);
rect(x2,d,a,a);
rect(x4,d,a,a);
}
else{
if(key=='r'||key=='R')
{
fill(255,0,0);
rect(x4,d,a,a);
fill(255);
rect(x1,d,a,a);
rect(x2,d,a,a);
rect(x3,d,a,a);
}
else{fill(255);}
}
}
}
}

OUTPUTS:

Output 1
red
Output 2
blue
Output 3
yellow
Output 4
Green

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License