SOURCE

console 命令行工具 X clear

                    
>
console
let ball;
function setup(){
    createCanvas(600,600);
    background(200);
    ball = new ball(300,300,30,80,5,0.2);
}
function draw(){
    ball.translating();
    ball.drawing();
}
class ball{
    constructor(ballX, ballY, ballSize, ballColor,ballTSpeedx,ballTspeedy){ 
            this.ballx = ballX; 
            this.bally = ballY;
            this.ballsize = ballSize;
            this.ballcolor = ballColor; 
            this.ballspeedx = ballTSpeedX; 
            this.ballspeedy = ballTspeedY;
    } 
    
    translating(){ 
        push();
        translate(this.ballx,this.bally);
        this.ballx +=random(-this.ballTSpeedX,this.ballTSpeedX); 
        this.bally +=random(-this.ballTspeedY,this.ballTspeedY);
    }  
    drawing() {
        fill(this.ballColor); 
        rect(0,0,this.ballSize, this.ballSize); 
        pop();
    } 
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.1.9/p5.min.js"></script>