Hello,
The code below compiles, but the way the words are displayed is really strange (last word on the left and then the other words on its right…) how come ?!!
I want to sort the words in alphabetical order and change their coordinates according to mouseX
A-words at the top, then B-words below and so on according to their index.
Thanks a lot already for your help.
Best,
L
String wordsList="afaint,afar,all,and,away,folly,for,from,given,glimpse,is,need,over,see,seeing,seem,that,the,there,this,to,where,what,word,";
String message;
String []lines;
boolean drawText;
PFont font;
String [] words;
//*****************************************************************************************************************************************
void setup() {
size(1080, 1600);
lines = loadStrings("Beckett.txt"); //link to the text
message= join(lines, " "); // join all the words together
lines= split(message, ","); //split the text line by line
words = splitTokens(message, " "); // now split each line into words?!
font = createFont("helvetica", 30);
textFont(font);
textAlign(LEFT);
}
//*****************************************************************************************************************************************
void draw() {
background(0);
translate(500, 100);
smooth();
int posX = 0;
int posY = 0;
for (int j=0; j<words.length; j++) {
int index = wordsList.indexOf(words[j]);
//if (index<0) continue;
float m=map(mouseX, 50, width-50, 0, 1);
m = constrain(m, 0, 1);
//float sortX = 0;
//float interX = lerp(posX, sortX, m);
float sortY =index*10+30;
float interY = lerp(posY, sortY, m);
posX +=textWidth(words[j])+10;
if (words[j].equals(",") || words[j].indexOf(",")>0) {
// new line
posX=0;
posY += 40;
}
fill(255);
text(words[j], posX, interY);
}
}