xxxxxxxxxx
66
// Defining the functions
let a = x => {
return 240 - 100 * sin((x - 245) * (x - 245) / 10000 + 1);
}
let b = x => {
return 340 - 100 * sqrt((x - 320) * (x - 320) / 10000 + 1);
}
let aPath = [];
let bPath = [];
let spacing = 1;
let t = 0;
let play = true;
function setup() {
createCanvas(640, 480);
for (let i = width / 3; i < width * 2 / 3; i += spacing) {
let xa = i - 150;
let ya = a(i);
let va = createVector(xa, ya);
aPath.push(va);
let xb = i + 150;
let yb = b(i);
let vb = createVector(xb, yb);
bPath.push(vb);
}
}
function keyPressed() {
if (key == " ") {
if (play) {
play = false;
} else {
play = true;
}
}
}
function draw() {
background(255);
stroke(0);
noFill();
strokeWeight(3);
beginShape();
let time = (sin(t) + 1) / 2;
if (play) {
t += 0.03;
}
for (let i = 0; i < aPath.length; i++) {
let qv = aPath[i];
let cv = bPath[i];
let x = lerp(qv.x, cv.x, time);
let y = lerp(qv.y, cv.y, time);
vertex(x, y);
}
endShape();
fill(0);
noStroke();
textAlign(CENTER);
textSize(40);
text("Playing: " + play, width / 2, 50);
}