Parsing text with proHtml and printing random words to the screen
in
Contributed Library Questions
•
7 months ago
Hi,
I am running into some trouble with printing random words (using text()) found in parsing an html file. I can use println(), and actually get it to work; however, I want to display text on a different screen instead.
The error that I'm getting is 'The method text(String, float, float) in the type PApplet is not applicable for the arguments (String)'. I know that I need to convert my float (or is it an int) to a string somehow, but I have so much info going on that I can't easily find a solution. I would be very grateful if anyone can give me a solution!
Here's the code:
import prohtml.*;
import java.util.regex.*;
PrintWriter txtfile;
HtmlList htmlList;
PFont myFont;
void setup(){
size(500,500);
background(255);
myFont = createFont("Rockwell", 48);
textFont(myFont);
frameRate(10);
//enter your url here
htmlList = new HtmlList("http://en.wikipedia.org/wiki/Life");
String s_list = "";
for (int i = 0;i<htmlList.pageList.size();i++){
String s = htmlList.pageList.get(i).toString();
Pattern p = Pattern.compile("<");
Matcher m = p.matcher(s);
boolean found = m.find();
if (found == false){
s_list = s_list.concat(s + " ");
}
}
//println(s_list);
Pattern q = Pattern.compile("[L|l]ife\\s[A-Za-z]+\\s[A-Za-z]+");
Matcher n = q.matcher(s_list);
String word_list[] = split(s_list, ' ');
saveStrings("html_input.txt", word_list);
}
void draw() {
String[] words = loadStrings("html_input.txt");
int pastIndex = int(random(words.length));
int presentIndex = int(random(words.length));
int futureIndex = int(random(words.length));
println(words[pastIndex]);
String past = (words[pastIndex]);
textAlign(CENTER, TOP);
text(past);
//textAlign(CENTER, CENTER);
//text(words[presentIndex]);
//textAlign(CENTER, BOTTOM);
//text(words[futureIndex]);
}
1