Change the color

Processing code written for changing colors on the screen using different key strokes.

Program :

//The program uses keys - 'a','b','c','d' to bring 4 different colors to the screen.

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=='a'||key=='A')
  {
    stroke(255,255,0);
    fill(255,255,0);
    rect(0,0,145,145);
  }
  else{fill(255);}
  if(key=='b'||key=='B')
  {
    stroke(0,255,0);
    fill(0,255,0);
    rect(155,0,145,145);
  }
  else{fill(255);}
  if(key=='c'||key=='C')
  {
    stroke(0,0,255);
    fill(0,0,255);
    rect(0,155,145,145);
  }
  else{fill(255);}
  if(key=='d'||key=='D')
  {
    stroke(255,0,0);
    fill(255,0,0);
    rect(155,155,145,145);
  }
  else{fill(255);}
}

Output :

Push key 'a'
1

Push key 'b'
2.JPG

Push key 'c'
3.JPG

Push key 'd'
4.JPG


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