Text animation problem
in
Programming Questions
•
1 year ago
Hi--I'm trying to write a program that takes a text file as input (file is variable size, but usually runs around 1,000 words), and uses words from the file in an animation in which the words move around randomly. In the program that I have so far, the words appear (and disappear, depending on whether or not I rewrite the background), but they don't move. Any help appreciated! Here's the code:
BufferedReader reader;
boolean readerFinished;
PFont f;
float speed = 0.02;
int n = 1000;
String[] word = new String[n];
float[]xspeed = new float[word.length];
float[]yspeed = new float[word.length];
float[]xpos = new float[word.length];
float[]ypos = new float[word.length];
///////////////////////////////////////// BEGIN SETUP //////////////////////////////
void setup() {
size (1000, 300);
f = createFont("Arial", 20, true);
reader = createReader ("AI.txt");
for (int i=0; i < word.length; i++){
xspeed[i] = random(-speed, speed); // SET VARIED SPEEDS
yspeed[i] = random(0.1, speed);
xpos[i] = width/2 + random(-width/1, width/1); // SET INITIAL PLACEMENT
ypos[i] = height/2 + random(-height/1, height/1);
}
frameRate (30);
} //////////////////////////////////////// BEGIN DRAW LOOP ////////////////////////
void draw() {
// background (255);
try {
String line = reader.readLine();
if (line != null) {
String[] word = splitTokens (line, " .,/;:[]?-()!\u2014\"");
println (word);
println (word.length);
fill (random(255), 0, 0);
textFont(f, random(12, 40));
background (255);
for (int i = 0; i < word.length; i++) {
text (word[i], xpos[i], ypos[i], width/3, height/3);
xpos[i] += xspeed[i];
ypos[i] += yspeed[i];
delay (40);
}
}
}
catch (IOException e) {
e.printStackTrace();
readerFinished = true;
}
} /////////////////////////////////////// END DRAW LOOP //////////////////////////
BufferedReader reader;
boolean readerFinished;
PFont f;
float speed = 0.02;
int n = 1000;
String[] word = new String[n];
float[]xspeed = new float[word.length];
float[]yspeed = new float[word.length];
float[]xpos = new float[word.length];
float[]ypos = new float[word.length];
///////////////////////////////////////// BEGIN SETUP //////////////////////////////
void setup() {
size (1000, 300);
f = createFont("Arial", 20, true);
reader = createReader ("AI.txt");
for (int i=0; i < word.length; i++){
xspeed[i] = random(-speed, speed); // SET VARIED SPEEDS
yspeed[i] = random(0.1, speed);
xpos[i] = width/2 + random(-width/1, width/1); // SET INITIAL PLACEMENT
ypos[i] = height/2 + random(-height/1, height/1);
}
frameRate (30);
} //////////////////////////////////////// BEGIN DRAW LOOP ////////////////////////
void draw() {
// background (255);
try {
String line = reader.readLine();
if (line != null) {
String[] word = splitTokens (line, " .,/;:[]?-()!\u2014\"");
println (word);
println (word.length);
fill (random(255), 0, 0);
textFont(f, random(12, 40));
background (255);
for (int i = 0; i < word.length; i++) {
text (word[i], xpos[i], ypos[i], width/3, height/3);
xpos[i] += xspeed[i];
ypos[i] += yspeed[i];
delay (40);
}
}
}
catch (IOException e) {
e.printStackTrace();
readerFinished = true;
}
} /////////////////////////////////////// END DRAW LOOP //////////////////////////
1