xxxxxxxxxx
34
let sx, sy, x, y;
function setup() {
createCanvas(400, 400);
sx = width/2;
sy = height/2;
x = sx;
y = sy;
}
function draw() {
background(255);
let slope = map(mouseY, 0, height, -10, 10);
let speed = map(mouseX, 0, width, 0, 10);
let xspeed = 1;
let yspeed = xspeed *slope;
let rspeed = dist(0, 0, xspeed, yspeed);
xspeed /= rspeed;
yspeed /= rspeed;
xspeed *= speed;
yspeed *= speed;
x += xspeed;
y += yspeed;
line(sx, sy, x, y);
if(y > height || y < 0) y = height/2;
if( x > width || x < 0) x = width/2;
}