Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

How to 'store' previous keyPressed data in the same sketch

$
0
0

Screen Shot 2018-04-12 at 7.18.27 PM

I can get one colored bar to expand as I hold down the key. I have another an issue of getting another colored bar to continue where the other one left off? Essentially it continues right after the previous rectangle depending on where it stops. Here's a picture of what I want to achieve (assuming each colored rectangle is a different length).

Here is my code:

int rectWidth=0;
int rectHeight=250;

int x = -rectWidth;  

void setup(){
  size(800,800);
  background(0);
  noStroke();
  smooth();

}

void draw(){

 rect(0, 0, rectWidth, rectHeight);

 if(keyPressed){
   rectWidth++;


  if((key == 'a')) {
   fill(#8fcd9c); }

 if((key == 'b')) {
    fill(#96c6ea); }

 if((key == 'c')) {
    fill(#ef3942); }

 if((key == 'd')) {
    fill(#fdf04d); }

 if((key == 'e')) {
    fill(#c6e9f6); }

 if((key == 'f')) {
    fill(#ef5a7a); }

 if((key == 'g')) {
    fill(#f8971d); } 
 }

Viewing all articles
Browse latest Browse all 2896

Trending Articles