Hey.
I am quite new to processing so excuse me if my explanation of this is in the wrong terms or if things are slightly misunderstood.
I am working on a code that write random words from a text on the screen every time the mouse is clicked. What I want it to do in the end is to use ALL the words randomly from the text, and when all the words is used, the whole process should start over from a blank screen. These two last steps I haven’t been able to implement. So far the code takes random words from the text and put’s them on the screen, but I have no guarantee that the same word won’t get repeated(of course the same word can appear as many times as it appears in the text). So as I see it, I want to avoid the same index number from the array being used more than one time. I also want everything to reset when the last index number is used.
To summarize what I want to implement:
- I want all the index numbers of the array used without having any duplicates.
- When all the index numbers is used, I want everything to start over from a blank screen.
Hope you understand.
Here is my code:
String[] words;
boolean newWord = false;
float x = 25;
float y = 40;
void setup() {
fullScreen();
background(0);
}
void draw() {
String[] lines = loadStrings("Skabelsesberetningen.txt");
String entireplay = join(lines, " ");
entireplay = entireplay.toLowerCase();
printArray(entireplay);
words = split(entireplay, " ");
words = splitTokens(entireplay, ":!?/()| ");
println(entireplay);
noLoop();
PFont f = createFont("Foundry Flek Grid", 18);
int index = int(random(words.length));
if (newWord) {
textFont(f);
text(words[index], x, y);
x += textWidth(words[index] + " ");
}
if (x > width-85) {
x = 25;
y += 20;
}
}
void mousePressed() {
loop();
newWord = true;
}
Any suggestions?
Thanks, Jonathan