SOURCE

var p;
var probability = 0.6;

function setup(){
  createCanvas(400, 200);
  p = new hello()
  background(0);
}
function draw(){
  p.run()
}

class hello {
  constructor(){
    this.x = 100;
    this.y = 100;
  }
  run(){
    this.update();
    this.show();
  }
  show(){
    stroke(0, 255, 0)
    point(this.x, this.y, 30)
  }
  update(){
    var x = random(1);
    var y = random(1);
    
    if(this.x < mouseX){
      if(x <= probability){
        this.x++
      }else{
        this.x--
      }
    }
    if(this.x > mouseX){
      if(x <= probability){
        this.x--
      }else{
        this.x++
      }
    }

    if (this.y < mouseY) {
      if(y <= probability){
        this.y++
      }else{
        this.y--
      }
    }
    if(this.y > mouseY){
      if(y <= probability){
        this.y--
      }else{
        this.y++
      }
    }
    this.x = constrain(this.x, 0, width-1);
    this.y = constrain(this.y, 0, height-1);
  }
}
console 命令行工具 X clear

                    
>
console