xxxxxxxxxx
42
let pos
let mvmt = 3
let mvmtY = 5
function setup() {
createCanvas(400, 400);
pos = createVector(width/2, height/2)
}
function draw() {
background(220, 100);
strokeWeight(10)
stroke("red")
point(pos.x, pos.y)
pos.x += mvmt
pos.y += mvmtY
//mvmtY += 20
if ((pos.x >= width && mvmt > 0) || (pos.x <= 0 && mvmt < 0)) {
mvmt *= -1
}
if ((pos.y >= height && mvmtY > 0) || (pos.y <= 0 && mvmtY < 0)) {
mvmtY *= -1
}
stroke(0)
point(mouseX, mouseY)
if (abs(pos.x - mouseX) < 10 && abs(pos.y - mouseY) < 10) {
mvmt *= -1
mvmtY *= -1
}
}