xxxxxxxxxx
37
let canvasWidth = 400;
let canvasHeight = 400;
let inputString = "hello world"
let charSpace;
let amplitude = 25; // size of wiggle
let buffer = 100;
let phase = 0.5; //speed in seconds. not quite sure what happens in that second, but it sure does.
let fontSize = 100;
function setup() {
createCanvas(canvasWidth, canvasHeight);
charSpace = canvasWidth / (inputString.length + 1);
amplitude = (canvasHeight) / 4;
fontSize = charSpace;
textSize(fontSize);
}
function draw() {
background(220);
for (let i = 0; i < inputString.length; i ++) {
//let x = charSpace * (i + 0.5);
//let y = amplitude * sin(i - (millis() * 0.001 * phase)) + canvasHeight * 0.5;
let x = amplitude * cos(i * (2 * PI / (inputString.length + 1)) + (millis() * 0.001 * phase)) + canvasWidth * 0.5;
let y = amplitude * sin(i * (2 * PI / (inputString.length + 1)) + (millis() * 0.001 * phase)) + canvasHeight * 0.5;
x += 0.5 * amplitude * cos(i * (2 * PI / (inputString.length + 1)) + 2 * (millis() * 0.001 * phase));
y += 0.5 * amplitude * sin(i * (2 * PI / (inputString.length + 1)) + 2 * (millis() * 0.001 * phase));
text(inputString[i], x, y);
}
}