Hello,
I got some amazing help from the great @jeremydouglass for my sketch, but I am stuck now.
Jeremy wrote me this below, but I don’t find the solution to write properly the function he suggested to me.
Blockquote
"It seems like you want to do word-level manipulations, then produce a mapping of the new positions.
So you want something like this:
“one for all”
designated as [0, 1, 2]
and then you want to give the input [2, 1, 0]
and produce “all for one” – is that correct?
So the function should accept two things – a String, and an int word order number sequence – and it should return an int of the letter id order
int[] order1 = new int[] {0, 1, 2};
int[] origins = targetPositions("one for all", order1);
println(origins);
0, 1, 2, -1, 3, 4, 5, -1, 6, 7, 8
int[] order2 = new int[] {2, 1, 0};
int[] targets = targetPositions("one for all", order2);
println(targets);
6, 7, 8, -1, 3, 4, 5, -1, 0, 1, 2
now you can find a target for each id, get the position of that target, and lerp to it.
for (int i=0; i<targets.length; i++) {
PVector targetPos = posFromID(targets[i]);
PVector pos = PVector.lerp(originPos[i], targetPos, amt);
}
"
Blockquote
Here is my bad attempt below. I managed to get this :
println(origins);
> 0, 1, 2, -1, 3, 4, 5, -1, 6, 7, 8
(FULL CODE BELOW )
but don’t manage to change the words order… How should I procceed.
Thanks a lot for your help.
best wishes,
Laurent
String message;
PVector []originPos;
PVector[] targetsPos;
PVector []posFromID;
int[]targets;
float arcLength;
PVector pos = new PVector(0, 0);
String []st ;
String [] wordsList;
int []origins;
float amt=0.02;
String m;
float rad =200;
String s = "one for all";
char [] c;
int[] order;
void setup() {
size(1000, 1000);
textFont(createFont ("Lucida sans", 20));
textSize(30);
textAlign(CENTER, CENTER);
st = split(s, ' ');
message = join(st, ' ');
targetsPos = chosenPos(message.length());
originPos = chosenPos(message.length());
for (int i=0; i<message.length(); i++) {
char [] c = new char[message.length()];
c[i] =message.charAt(i);
}
for (int i=0; i<message.length(); i++) {
targets = new int [message.length()];
}
}
void draw() {
background(0);
arcLength=0;
translate(width/2, height/2);
for (int i=0; i<message.length(); i++) {
char [] c =message.toCharArray();
char currentChar = message.charAt(i);
float w = textWidth(currentChar);
arcLength +=w/2+10;
float theta = PI+arcLength/rad;
targetsPos[i].x = cos(theta)*rad;
targetsPos[i].y = sin(theta)*rad;
originPos[i].lerp(targetsPos[i], 0.02);
// draw words + rect
pushMatrix();
translate(originPos[i].x, originPos[i].y);
rotate(theta+PI/2);
noFill();
stroke(255, 0, 0, 200);
strokeWeight(3);
rect(0, 0, 10, 10);
fill(255, 200);
text(c[i], 0, 0);
popMatrix();
arcLength+=w/2;
}
}
/*--------------------------------------------------------------------------------------------------------------------------------------------------------*/
void keyReleased() {
if (key=='0') {
int[] order1 = new int[] {0, 1, 2};
int[] origins = targetPositions(s, order1);
println(order1);
println(origins);
} else if (key=='1') {
int[] order2 = new int[] {2, 1, 0};
int[] targets = targetPositions(s, order2);
println(order2);
println(targets);
}
}
/*--------------------------------------------------------------------------------------------------------------------------------------------------------*/
PVector[] chosenPos(int count) {
PVector[] originPos = new PVector[count];
for (int i=0; i<message.length(); i++) {
originPos[i] = new PVector(0, 0);
}
return originPos;
}
/*--------------------------------------------------------------------------------------------------------------------------------------------------------*/
int [] targetPositions (String s, int[]order) {
String[]st = split(s, " ");
String [] ns = new String [st.length];
ns[0] = st[order[0]];
ns[1] = st[order[1]];
ns[2] = st[order[2]];
ns=st;
s=join(st, ' ');
int [] origins = new int[s.length()];
PVector [] np = new PVector [s.length()];
for (int i=0; i<st.length; i++) {
for (int j=0; j<s.length(); j++) {
if (order[i]==0) {
st[0] = "one";
st[0] = s.substring(0, 2);
origins[0]=s.indexOf('o');
origins[1]=s.indexOf('n');
origins[2]=s.indexOf('e');
np[0]=originPos[origins[0]];
np[1]=originPos[origins[1]];
np[2]=originPos[origins[2]];
}
origins[3]=s.indexOf('$');
if (order[i]==1) {
st[1] = "for";
st[1] = s.substring(4, 6);
origins[4]=s.indexOf('f')-1;
origins[5]=s.indexOf(st[1], 1);
origins[6]=s.indexOf('r')-1;
np[4]=originPos[origins[4]];
np[5]=originPos[origins[5]];
np[6]=originPos[origins[6]];
}
origins[7]=s.indexOf('$');
if (order[i]==2) {
st[2] = "all";
st[2]= s.substring(8, 10);
origins[8]=s.indexOf('a')-1;
origins[9]=s.indexOf('l')-1;
origins[10]=s.indexOf('l');
np[8]=originPos[origins[8]];
np[9]=originPos[origins[9]];
np[10]=originPos[origins[10]];
}
}
}
return origins;
}
/*--------------------------------------------------------------------------------------------------------------------------------------------------------*/