Assignment 3

Colour Change on Key Press

In this assignment we had to write a program by which we can change the colour of sqaures on the screen.
Here basically the If/Else loop has been used.And four keys were assigned the job of changing the colours.

The screen shots :

When key '1' is pressed

11.JPG

When key '2' is pressed

22.JPG

When key '3' is pressed
33.JPG

When key '4' is pressed

44.JPG

'PROCESSING' Code

void setup()
{
size(700,700);

}
void draw() {
fill(255);
rect(0, 0, 350, 350);
fill(255);
rect(350, 350, 700, 700);
fill(255);
rect(0, 350, 350, 350);
fill(255);
rect(350, 0, 350, 350);

if(keyPressed) {
if (key == 'a' || key == '1') {
fill(255,0,0);
}
else {
fill(255);
}
rect(0, 0, 350, 350);

if (key == 'b' || key == '2') {
fill(0,255,0);
}
else {
fill(255);
}
rect( 350, 350, 700, 700);

if (key == 'c' || key == '3') {
fill(0,0,255);
}
else {
fill(255);
}
rect(0, 350, 350, 350);

if (key == 'd' || key == '4') {
fill(255,255,0);
}
else {
fill(255);
}
rect(350, 0, 350, 350);
}
fill(255);

}

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