The current state is as shown in the figure, with “a” as the axis of movement, how to move with “d” as the axis in the current cycle?
Here’s the current code, thanks for your help!
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
let tSize = 40;
let distance = map(sin(frameCount * 0.04), -1, 1, 0, 80);
leftAlign("abcd", 100, height/2, distance, tSize);
}
function leftAlign(strings, posX, posY, distance, tSize) {
noStroke();
textSize(tSize);
push();
translate(posX, posY);
for (let i = 0; i < strings.length; i++) {
let x = i * distance;
text(strings[i], x, 0);
}
pop();
}
I tried to write a new function to achieve the desired effect, by rearranging the content array.
function rightAlign(strings, posX, posY, distance, tSize) {
let stringsArray = strings.split("").reverse();
noStroke();
textSize(tSize);
push();
translate(posX, posY);
for (let i = 0; i < strings.length; i++) {
let x = -i * distance;
text(stringsArray[i], x, 0);
}
pop();
}
But how can we achieve this effect through the positional algorithm without changing the order of the array.