like a heat sensitive map

edited April 2014 in How To...

hey guys for my class i want to "map" out different words. My idea was to have each word( in total 8) represent a shape and depending on the color would should the amount of time it was used. If this is possible i would greatly appreciate it, its due april 23 at 8am and i want enough before the project is due in case i have to come up with something else.

Thanks HD

Answers

  • String source = "My dog is a better at being a dog than that cat ever could be.";
    String[] words = {"dog", "that", "arf", "cat", "my", "a"};
    int[] counter;
    int max_count = 0;
    
    void setup(){
      size(400,400);
      textAlign(CENTER, CENTER);
      counter = new int[words.length];
      String[] temp = source.split(" ");
      for(int w=0; w<words.length; w++){
        for(int s=0; s<temp.length; s++){
          if(words[w].equals(temp[s])){
            counter[w]++;
          }
        }
        println("Word '" + words[w] + "' appears " + counter[w] + " time(s).");
        if( counter[w] > max_count){
          max_count = counter[w];
        }
      }
    }
    
    void draw(){
      background(0);
      translate(width/2,height/2);
      for( int c=0; c<counter.length; c++){
        pushMatrix();
        rotate(map(c, 0, counter.length, 0, TWO_PI));
        translate(100,0);
        noStroke();
        fill(map(counter[c],0,max_count,0,255), 0, 0);
        rect(-20,-20,40,40);
        fill(255);
        text("" + words[c] + ": " + counter[c], 0,0);
        popMatrix();
      }
    }
    
Sign In or Register to comment.