Key

edited November 2013 in How To...

Am stuck in writting the following

Answers

  • Looks like an assignment, we generally avoid giving the solution to these, but we are ready to help / guide you. (Note that we don't have a MapThing handy, probably, so it is hard to build on something we ignore.)

    So, what you have tried so far? Are you stuck at a given point? Where do you need help?

  • Is is just an exercise for self study. I tried but nothing is running.

  • Show your code.

  • Hey ya! I did a template for key toggle state; so you gotta a place to start: =:)

    // forum.processing.org/two/discussion/949/key-pressed
    
    final static int REGIONS = 0, ROADS = 1, RIVERS = 2;
    int selection = REGIONS;
    
    boolean showAirports = true, showTowns = true, showPans = true;
    
    void setup() {
      size(250, 250);
      smooth();
    
      noLoop();
      frameRate(5);
    
      textSize(030);
      fill(#E0F040);
    }
    
    void draw() {
      clear();
    
      text("[A]irports:  " + showAirports, 40, 50);
      text("[T]owns:    "  + showTowns, 40, 100);
      text("[P]ans:      " + showPans, 40, 150);
      text("[R]egions:   " + selection, 40, 200);
    }
    
    void keyPressed() {
      switch (keyCode) {
      case 'A':    
        showAirports = !showAirports;
        break;
    
      case 'T':
        showTowns = !showTowns;
        break;
    
      case 'P':
        showPans = !showPans;
        break;
    
      case 'R':
        selection = (selection + 1) % 3;
      }
    
      redraw();
    }
    
Sign In or Register to comment.