xxxxxxxxxx
63
let numero_punti = 2;
let x = [numero_punti];
let y = [numero_punti];
let punto_corda_x, punto_corda_y;
let quiete_x, quiete_y;
let dir_x = 1, dir_y = 1;
let vel = 5;
let amp_x = 0, amp_y = 0;
let fr = 0;
function setup() {
createCanvas(400, 400);
//frameRate(60)
x[0] = 20;
y[0] = 20;
x[1] = 380;
y[1] = 380;
quiete_x = (x[0] + x[1]) * 0.5;
quiete_y = (y[0] + y[1]) * 0.5;
punto_corda_x = quiete_x;
punto_corda_y = quiete_y;
}
function draw() {
background(50);
noFill();
stroke(255);
/*curve( width - mouseX, height - mouseY,20, 20, 350, 350, width - mouseX, height - mouseY); */
if (mouseIsPressed) {
punto_corda_x = mouseX;
punto_corda_y = mouseY;
amp_x = (punto_corda_x - quiete_x)
amp_y = (punto_corda_y - quiete_y)
fr = PI;
}
else {
amp_x = amp_x * 0.988;
punto_corda_x = quiete_x + amp_x * sin(0.5*fr);
amp_y = amp_y * 0.988;
punto_corda_y = quiete_y + amp_y * sin(0.5*fr);
fr++;
}
beginShape();
curveVertex(x[0], y[0]);
curveVertex(x[0], y[0]);
curveVertex(punto_corda_x, punto_corda_y);
curveVertex(x[1],y[1]);
curveVertex(x[1],y[1]);
endShape();
}