Scanning words from a list
              in 
             Programming Questions 
              •  
              1 year ago    
            
 
           
             Dear all interested readers,
            
            
            
I'm working on a code that scans a text for specific words and give the block behind the word a specific color.
            
example of how I do this:
            
if ("het".equals(theword) == true) {
fill(0, 150, 0);
}
if ("de".equals(theword) == true) {
fill(0, 150, 0);
}
if ("een".equals(theword) == true) {
fill(0, 150, 0);
}
 
            
if ("aan".equals(theword) == true) {
fill(200, 0, 0);
}
            
            
It seems a bit weird to call the code for "de"+"het"+"een" 3 times, since the results have to be the same. Is it posible to have a list of these words: list = de, het, een, and then check the whole list at once?
            
Here's my entire code:
            
            
            
Hope that someone can give me tips on how to solve this.
            
            
Thanks in advance
 
           
 
            
           I'm working on a code that scans a text for specific words and give the block behind the word a specific color.
example of how I do this:
if ("het".equals(theword) == true) {
fill(0, 150, 0);
}
if ("de".equals(theword) == true) {
fill(0, 150, 0);
}
if ("een".equals(theword) == true) {
fill(0, 150, 0);
}
if ("aan".equals(theword) == true) {
fill(200, 0, 0);
}
It seems a bit weird to call the code for "de"+"het"+"een" 3 times, since the results have to be the same. Is it posible to have a list of these words: list = de, het, een, and then check the whole list at once?
Here's my entire code:
- boolean kollom1 = true;
 boolean kollom2 = false;
 int teller;
 int kollom = 30;
 int timer;
 PFont reg;
 PFont reg2;
 float textbreedte;
 PFont number;
 String[] origtext;
 int counter;
 String delimiters =" ,.?!;:[]><-";
 float yplaats = 28;
 import processing.pdf.*;
 boolean record = false;
 int telx;
 int tely;
 int imagecount;
 PImage img;
 int increment=1;
 void setup() {
 size(1100, 850);
 reg = createFont("Arial", 55);
 reg2 = createFont("Arial", 25);
 String[]rawtext = loadStrings("test.txt");
 String all = join(rawtext, "");
 origtext=splitTokens(all, delimiters);
 noStroke();
 background(255);
 }
 void draw() {
 
 fill(255);
 if (record == false) {
 beginRecord(PDF, "frame-####.pdf");
 record = true;
 }
 if (counter < origtext.length) {
 String theword = origtext[counter];
 int total = 0;
 for (int i =0; i < origtext.length; i++) {
 if (theword.equals(origtext[i])) {
 total++;
 }
 }
 noStroke();
 // rect(0,0,width/4,height-total);
 textFont(reg2);
 float balk2 = textWidth(theword);
 noStroke();
 if (total > 1 && total <5) {
 fill(0, 0, 255);
 }
 else {
 fill(0);
 }
 if (total > 5 && total <8) {
 fill(255, 100, 30);
 }
 if ("you".equals(theword) == true) {
 fill(115, 0, 250);
 }
 if ("de".equals(theword) == true) {
 fill(0, 150, 0);
 }
 
 if ("het".equals(theword) == true) {
 fill(0, 150, 0);
 }
 
 if ("een".equals(theword) == true) {
 fill(0, 150, 0);
 }
 if ("in".equals(theword) == true) {
 fill(255, 0, 0);
 }
 if ("om".equals(theword) == true) {
 fill(255, 0, 0);
 }
 
 if ("op".equals(theword) == true) {
 fill(255, 0, 0);
 }
 if ("van".equals(theword) == true) {
 fill(255, 0, 0);
 }
 if ("om".equals(theword) == true) {
 fill(255, 0, 0);
 }
 if ("Van".equals(theword) == true) {
 fill(255, 0, 0);
 }
 if ("voor".equals(theword) == true) {
 fill(255, 0, 0);
 }
 if ("over".equals(theword) == true) {
 fill(255, 0, 0);
 }
 if ("bij".equals(theword) == true) {
 fill(255, 0, 0);
 }
 if ("met".equals(theword) == true) {
 fill(255, 0, 0);
 }
 if (textbreedte+balk2 > width-50) {
 textbreedte = 0;
 yplaats = yplaats+28;
 }
 if (yplaats > height-60) {
 yplaats = 28;
 if (record == true) {
 endRecord();
 record = false;
 }
 background(255);
 }
 // fill(0);
 
 if (record == false) {
 
 } else{
 rect(textbreedte, yplaats+5, balk2+7, 28);
 fill(255);
 textFont(reg2);
 text(theword, textbreedte+1, yplaats+26);
 textbreedte = textbreedte+balk2+7;
 }
 }
 else {
 println("done");
 endRecord();
 }
 // counter = (counter + 1)%origtext.length;
 if (counter < origtext.length) {
 teller = teller+1;
 counter = origtext.length-origtext.length+teller;
 }
 }
Hope that someone can give me tips on how to solve this.
Thanks in advance
 
              
              1  
            
 
            
 
 
           
 
             
 
            