xxxxxxxxxx
50
let c = 0;
let sx, sy, tsx, tsy, ex, ey, x, y;
let xspeed, yspeed;
let go;
function setup() {
createCanvas(windowWidth, windowHeight);
tsx = width / 2;
tsy = 0;
sx = tsx;
sy = tsy;
ex = sx;
ey = 10;
init();
stroke(255);
}
function draw() {
background(0);
if (go) {
x += xspeed;
y += yspeed;
}
line(sx, sy, x, y);
}
function init() {
sx = tsx;
sy = tsy;
x = sx;
y = sy;
xspeed = (ex - tsx) / 10;
yspeed = (ey - tsy) / 10;
go = true;
}
function mousePressed() {
go = false;
c++;
if (c % 2 == 0) {
ex = mouseX;
ey = mouseY;
init();
} else {
tsx = mouseX;
tsy = mouseY;
}
}