Changing color on key press

Processing programme

The program to change the colors using keys 1,2,3,4

void setup()
{
size(300,300);
background(255);
}

void draw()
{
strokeWeight(15);
stroke(3,3,3);
line(150,0,150,300);
line(0,150,300,150);
}

void keyPressed()
{
if(key=='1')
{
stroke(255,255,0);
fill(255,255,0);
rect(0,0,145,145);
}
else{fill(255);}
if(key=='2')
{
stroke(0,255,0);
fill(0,255,0);
rect(155,0,145,145);
}
else{fill(255);}
if(key=='3')
{
stroke(0,0,255);
fill(0,0,255);
rect(0,155,145,145);
}
else{fill(255);}
if(key=='4')
{
stroke(255,0,0);
fill(255,0,0);
rect(155,155,145,145);
}
else{fill(255);}
}

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