Dear @jeremydouglass,
I have done this below, but I think there might be better ways to put that…
Two questions: how can I know the number of words in each line in order to know which String to put into each line?!
if (j2 <4) {
j=0;
}
if (j2 >4 && j2 < 9) {
j=1;
}
if (j2>9 && j2<18) {
j=2;
}
Second question: how can I use your magical lerp() ?! To go from one location to the next smoothly ?
for (int i=0; i<words.length; i++) {
// move word towards next target
pos[i].lerp(targets[i], 0.02);
text(words[i], pos[i].x, pos[i].y);
Here is the code below. Thank you very much in advance for your help!
Best wishes,
Laurent
import java.util.Map;
PFont font;
String[]lines={
"folly folly for to for to",
"what is the word",
"folly from this all this folly from all this"
/*"given folly given all this seeing folly seeing all this this",
"what is the word",
"this this this this here all this this here folly given all this",
"seeing folly seeing all this this here for to",
"what is the word",
"see glimpse seem to glimpse need to seem to glimpse folly for to need to seem to glimpse what",
"what is the word",
"and where folly for to need to seem to glimpse what where where what is the word there over there away over there",
"afar afar away over there",
"afaint afaint afar away over there what what",
"what is the word",
"seeing all this all this this all this this here folly for to see what glimpse seem to glimpse need to seem to glimpse",
"afaint afar away over there what",
"folly for to need to seem to glimpse afaint afar away over there what",
"what",
"what is the word",
"what is the word"*/
};
String alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ ";
String[] lines2;
String[] c1={};
String[] wordsList2;
int Size;
float r = 45;
Letter[]letters;
//Word[]words;
String message;
String[]wordsInThatLine;
String st;
float interY;
PVector [] pos;
PVector [] newPos;
float[]originPositionsX = new float [alphabet.length()];
float[]originPositionsY = new float [alphabet.length()];
float posX, posY;
// Note the HashMap's "key" is a String and "value" is an Integer
HashMap<String, Integer> hmYPos = new HashMap<String, Integer>();
//********************************************************************************************************************************************************
void setup() {
size(1400, 1400);
font = createFont("helvetica", 20);
textFont(font);
textAlign(CENTER, CENTER);
message = join(lines, ",");
lines = split(message, ",");
wordsList2 = split(join(lines, " "), " ");
letters = new Letter[message.length()];
pos = chosenPos(message.length());
newPos = chosenPos(message.length());
for (int i =0; i< message.length(); i++) {
letters[i]= new Letter(pos[i].x, pos[i].y, message.charAt(i), r);
//posX += textWidth(message.charAt(i));
}
prepare();
}
//********************************************************************************************************************************************************
void draw() {
background(0);
translate (width/2, height/2);
smooth();
scale(0.7);
float arcLength=0;
for (int j = 0; j < lines.length; j++) {
if ( j<=lines.length) {
r=45*j+1;
}
for (int j2 = 0; j2 < wordsList2.length; j2++) {
int index = hmYPos.get(wordsList2[j2]);
if (index<0) continue;
arcLength+=10;
mouseX = constrain(mouseX, width/2, width);
float sortY = 0;
r= map(mouseX, width/2, width, 75+45*j+1, 150+hmYPos.get(wordsList2[j2]));
sortY=r;
float m=map(mouseX, width/2, width, 0, 1);
m = constrain(m, 0, 1);
interY = lerp(posY, sortY, m);
for (int j3 = 0; j3 < wordsList2[j2].length(); j3++) {
String st=str(wordsList2[j2].charAt(j3)).toUpperCase();
char upperCaseChar = st.charAt(0);
int ind = alphabet.indexOf(upperCaseChar);
if (ind <0) continue;
if (originPositionsX[ind] !=0 && originPositionsY[ind] !=0) {
noFill();
strokeWeight(1);
stroke(255, 150, 0, 180);
bezier(originPositionsX[ind], originPositionsY[ind], letters[j3].x+50, letters[j3].y+100, letters[j3].x-20, letters[j3].y-30, letters[j3].x, letters[j3].y);
}
originPositionsX[ind]= letters[j3].x;
originPositionsY[ind]= letters[j3].y;
}
for (int j3 = 0; j3 < wordsList2[j2].length(); j3++) {
char currentChar= wordsList2[j2].charAt(j3);
float w=textWidth(currentChar);
arcLength+=w/2+10;
float theta = PI+arcLength/r;
newPos[j2].x = cos(theta)*r;
newPos[j2].y = sin(theta)*r;
letters[j3] = new Letter(newPos[j2].x, newPos[j2].y, currentChar, r);
pushMatrix();
translate(letters[j3].x, letters[j3].y);
rotate(theta+PI/2);
noFill();
strokeWeight(hmYPos.get(wordsList2[j2])*0.01+0.3);
stroke(0, 0, 150, 150);
ellipse(0, -40, hmYPos.get(wordsList2[j2])*0.07, hmYPos.get(wordsList2[j2])*0.07);
fill(255, 200);
textAlign(CENTER, CENTER);
float SText = hmYPos.get(wordsList2[j2])*0.035;
textSize(SText+20);
//pos[j2].lerp(newPos[j2], 0.02);
if (j2 <4) {
j=0;
}
if (j2 >4 && j2 < 9) {
j=1;
}
if (j2>9 && j2<18) {
j=2;
}
text(currentChar, pos[j2].x, pos[j2].y);
popMatrix();
w=textWidth(currentChar);
arcLength+=w/2;
}
}
}
}
void mouseReleased() {
reorder(0, 5, 11, 9, 17, 4, 15, 10, 1, 16, 8, 12, 3, 6, 13, 2, 14, 7, 18);
}
//---------------------------------------------------------------------------------------------------------------------------------------------
PVector[] chosenPos(int count) {
PVector []pos = new PVector [count];
for (int i =0; i<message.length(); i++) {
pos[i]= new PVector(0, 0);
}
return pos;
}
//---------------------------------------------------------------------------------------------------------------------------------------------
void reorder(int...idx) {
String []nw = new String [wordsList2.length];
nw[0]= wordsList2[idx[0]];
nw[1]=wordsList2[idx[1]];
nw[2]=wordsList2[idx[2]];
nw[3]=wordsList2[idx[3]];
nw[4]=wordsList2[idx[4]];
nw[5]=wordsList2[idx[5]];
nw[6]=wordsList2[idx[6]];
nw[7]=wordsList2[idx[7]];
nw[8]=wordsList2[idx[8]];
nw[9]=wordsList2[idx[9]];
nw[10]=wordsList2[idx[10]];
nw[11]=wordsList2[idx[11]];
nw[12]=wordsList2[idx[12]];
nw[13]=wordsList2[idx[13]];
nw[14]=wordsList2[idx[14]];
nw[15]=wordsList2[idx[15]];
nw[16]=wordsList2[idx[16]];
nw[17]=wordsList2[idx[17]];
nw[18]=wordsList2[idx[18]];
wordsList2 = nw;
PVector[]yValues = new PVector[wordsList2.length];
PVector[]wordsV = new PVector [wordsList2.length];
yValues[0] = wordsV[idx[0]];
yValues[1] = wordsV[idx[1]];
yValues[2] = wordsV[idx[2]];
yValues[3] = wordsV[idx[3]];
yValues[4] = wordsV[idx[4]];
yValues[5] = wordsV[idx[5]];
yValues[6] = wordsV[idx[6]];
yValues[7] = wordsV[idx[7]];
yValues[8] = wordsV[idx[8]];
yValues[9] = wordsV[idx[9]];
yValues[10] = wordsV[idx[10]];
yValues[11] = wordsV[idx[11]];
yValues[12] = wordsV[idx[12]];
yValues[13] = wordsV[idx[13]];
yValues[14] = wordsV[idx[14]];
yValues[15] = wordsV[idx[15]];
yValues[16] = wordsV[idx[16]];
yValues[17] = wordsV[idx[17]];
yValues[18] = wordsV[idx[18]];
yValues = wordsV;
}
//---------------------------------------------------------------------------------------------------------------------------------------------
void prepare() {
HashMap<String, Integer> hm1 = new HashMap<String, Integer>();
String message;
message= join(lines, " "); // Join all the separated strings
lines2=split(message, ",");// Split them into sentences according to the comas
// Now we have a copy of the whole text
// Init
wordsList2 = split(join(lines, " "), " ");
//println(wordsList2);// We do the same than above for a new copy to initialize the HashMap
for (String s : wordsList2) { // We loop across the whole list of strings
hm1.put(s.toLowerCase(), 0); // We fill the HashMap (hm1) and put the strings to lowerCase and put all at 0
textSize(abs(hm1.get(s)*5+Size)+15); // We pass a textSize
}
// Counting
for (int i=0; i<lines2.length; i++) { // We loop across the whole strings
String word = lines2[i].toLowerCase().trim(); // We put the strings to lowerCase and get rid of comas, points, etc.
if (hm1.get(word) != null) { // If the HashMap is not null
hm1.put(word, ((int) (hm1.get(word)))+1); // We fill the HashMap with the 2nd list of strings (word) and we add 1
}
}
//// Using an enhanced loop to iterate over each entry
for (Map.Entry me : hm1.entrySet()) {
c1 = (String[]) append (c1, me.getKey());
}//for
c1=sort(c1); //We sort the strings according to the alphabet
// simulate output and save the line number for each word in sorted position
int posY=0;
for (String s : c1) {
hmYPos.put( s, posY);
//Size=hmYPos.get(s);
posY += 25;
}
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------
class Letter {
char letter;
float x, y, r;
Letter(float _x, float _y, char _letter, float _r) {
x=_x;
y=_y;
r=_r;
letter=_letter;
}
void display() {
fill(255);
noStroke();
text(letter, x, y);
}
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------