Dear Jeremy,
I hardly have time to ‘code’. Here is below where I am now. I managed to create a letter class and to draw them, but I struggle with the lines between the letters, I tried with an alphabet.indexOf(upperCaseChar), but my lines don’t link all the same letters (a with all the a’s, b with all the b’s and so on). Can you tell me what is my mistake please ?!
Thank you very much in advance.
Best wishes,
L
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="ABCDEFGHIJKLMNOPQRSTUVWXYZ2019,.;:!?\n ";
// --------------------------------------------------------
String[] lines2;
String[] c1={};
String[] wordsList2;
int Size;
float r = 40;
float angle = 0;
Letter[]letters;
String message;
char lowerCaseChar;
float interY;
float stepX = 25;
String joinedText;
int ind;
float x, y;
// 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);
message = join(lines, ",");
lines = split(message, ",");
//println(message.length());
letters = new Letter[message.length()];
for (int i =0; i<message.length(); i++) {
letters[i]= new Letter(x, y, message.charAt(i), r);
}
prepare();
}
//********************************************************************************************************************************************************
void draw() {
background(0);
translate (width/2, height/2);
smooth();
scale(0.7);
float posX = 0;
float arcLength=0;
float posY = 0;
float[]originPositionsX = new float [alphabet.length()];
float[]originPositionsY = new float [alphabet.length()];
for (int j = 0; j < lines.length; j++) {
if ( j<=lines.length) {
r=45*(j+1);
}
String[]wordsInThatLine = split(lines[j], " ");
for (int j2 = 0; j2 < wordsInThatLine.length; j2++) {
int index = hmYPos.get(wordsInThatLine[j2]);
if (index<0) continue;
arcLength+=15;
mouseX=constrain(mouseX, width/2, width);
float sortY = 0;
r= map(mouseX, width/2, width, 75+45*j+1, 150+hmYPos.get(wordsInThatLine [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 < wordsInThatLine[j2].length(); j3++) {
char currentChar= wordsInThatLine[j2].charAt(j3);
letters[j3]= new Letter(posX, posY, currentChar, r);
float w=textWidth(currentChar);
arcLength+=w+5;
float theta =PI+arcLength/r;
pushMatrix();
translate(r*cos(theta), r*sin(theta));
scale(0.7);
rotate(theta+PI/2);
String joinedText = join(wordsInThatLine, " ");
String st=str(joinedText.charAt(j3)).toUpperCase();
char upperCaseChar= st.charAt(0);
ind = alphabet.indexOf(upperCaseChar);
if (ind < 0) continue;
noFill();
stroke(181, 157, 0, 250);
strokeWeight(1);
line(originPositionsX[ind], originPositionsY[ind], posX, interY);
noFill();
strokeWeight(hmYPos.get(wordsInThatLine[j2])*0.01+0.1);
stroke(0, 50, 220, 100);
//ellipse(0, -10, hmYPos.get(wordsInThatLine[j2])*0.07+15, hmYPos.get(wordsInThatLine[j2])*0.07+15);
fill(255, 200);
textAlign(CENTER, BASELINE);
float SText = hmYPos.get(wordsInThatLine[j2])*0.035;
textSize(SText+20);
letters[j3].display();
//text(currentChar, 0, 0);
popMatrix();
arcLength+=w/2;
}
}
}
originPositionsX[ind]= posX;
originPositionsY[ind]= interY;
}
//------------------------------------------------------------
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, " "), " "); // 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
//println(c1);
// 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);
}
}//
//