SOURCE

let angle = 0;
let len = 0;
let start = 30;

function setup() {
  createCanvas(400, 400);
}

function draw() {

    background(220);

    angle += 0.1;
    len += 0.3;

    let x = map(sin(angle) , -1 , 1 , len / 2 , start + len);

    let targetY1 = (height - (start + len - len / 2)) / 2;
    let targetY2 = targetY1 + (start + len - len / 2);
    let y = map(cos(angle) , -1 , 1 , targetY1 , targetY2);

    ellipse(x , y , 30);

}
* {
  margin: 0px;
}
body{
    padding: 10px;
}
canvas{
    border: 1px solid red;
}
console 命令行工具 X clear

                    
>
console