Greetings all,
I have this little bit of code to bounce around text read from a .txt file. I want it to make a separate "object" from each line of text and have them sort of bounce around independently, but I seem to have it running so that it is just making a growable array of chunks of all the lines of text. Does that make sense? It's putting all lines of text together rather than separating them, and I don't exactly know how to make them separate... I know it's not hard, but I just can't get my head around it. Help is appreciated!!!!
I have this little bit of code to bounce around text read from a .txt file. I want it to make a separate "object" from each line of text and have them sort of bounce around independently, but I seem to have it running so that it is just making a growable array of chunks of all the lines of text. Does that make sense? It's putting all lines of text together rather than separating them, and I don't exactly know how to make them separate... I know it's not hard, but I just can't get my head around it. Help is appreciated!!!!
ArrayList texts;
void setup(){
size(800,600);
//create an arraylist with nothing in it yet
texts = new ArrayList();
//start with one text block
texts.add( new Text (0,0,0,1,2,3) );
}
void draw(){
background(0);
fill(255,0,0);
String[] lines = loadStrings("sampleText.txt");
println("there are " + lines.length + "texts");
for (int i=0; i < lines.length; i++) {
//println(lines[i]);
texts.add( new Text (0,0,0,1,2,3) );
for (int j = texts.size()-1; j >= 0; j--){
Text text = (Text) texts.get(j);
text.moveTxt();
text.showTxt(lines[i]);
} //end texts for loop
} //end file load for loop
} //end draw
//text block class
class Text {
float xPos, yPos, zPos;
float xVel, yVel, zVel;
Text(float xP, float yP, float zP, float xV, float yV, float zV){
xPos = xP;
yPos = yP;
zPos = zP;
xVel = xV;
yVel = yV;
zVel = zV;
xVel = random(-5,5);
yVel = random(-5,5);
zVel = random(-5,5);
}
void moveTxt(){
xPos += xVel;
yPos += yVel;
zPos += zVel;
if(xPos > width || xPos < 0){
xVel *= -1;
}
if(yPos > height || yPos < 0){
yVel *= -1;
}
}
void showTxt(String nanka){
nanka = nanka;
text(nanka, xPos, yPos, zPos);
}
}//end class
1