xxxxxxxxxx
59
let mosue;
class C {
constructor(x, y, r) {
this.x = x
this.y = y
this.r = r
}
show() {
fill(255)
ellipse(this.x, this.y, this.r);
noFill()
ellipse(this.x, this.y, 200);
return dist(this.x,this.y,mouseX,mouseY)
}
move() {
if (dist(this.x, this.y, mouseX, mouseY) < 200) {
let dir = createVector(mouseX-this.x,mouseY-this.y);
dir.x = -0.0005*map(mouseX-this.x,-5,5,-1*dist(this.x, this.y, mouseX, mouseY),dist(this.x, this.y, mouseX, mouseY)); console.log("left")
// if (mouseX>this.x/*to the right*/) {
// dir.x *= 0.05*map(mouseX-this.x,0,5,5,0)}
console.log(dir.x)
// dir.y *= -0.0005*dist(this.x, this.y, mouseX, mouseY)
this.x += dir.x
this.y +=dir.y
// if (mouseX<this.x && mouseX>this.yn){x++;y++}
// if (mouseX>this.x && mouseX<this.yn){x--;y--}
// if (mouseX<this.x){this.x++}
// if (mouseX>this.x){this.x--}
// if (mouseX<this.y){this.y--}
// if (mouseX>this.yn){this.y++}
// this.y = this.y + dist(this.x,this.x,mouseX,mouseY)-100
// console.log(dir)
}
}
}
function setup() {
createCanvas(400, 400);
mosue = createVector(mouseX,mouseY)
}
let c1 = new C(150, 200, 25);
// let c2 = new C(200, 200, 25);
// let c3 = new C(250, 200, 25);
let d = null
function draw() {
background(220);
text(c1.show(), 200, 150)
mosue = createVector(mouseX,mouseY)
c1.show()
c1.move()
// c2.show()
// c3.show()
}