How to press space key to toggle doubling the size of the rectangle?

        float x = 400, y=100;
      int a=20,b=10;
      void setup() { size(800, 200); }
      void draw() {
      rect(x-10, y-5, a, b);
      }
      void keyPressed() {
        int k=' ';
      if (keyCode == RIGHT) {
      x++;
      } else if (keyCode == LEFT) {
      x--;
      } else if (keyCode == UP){
        y--;
      } else if (keyCode == DOWN){
        y++;
      }else if(key=' '){
       a=a*2;
       b=b*2;
        }
      }


Can you teach for me how to press space key you toggle by doubling the size of the rectangle, 1 time, 2 times, 1 time?

If you post your question to multiple sites, please link between those posts so we know what help you’ve already received.

This question has already been asked (and answered) here:

1 Like