SOURCE

class RotatingSquare{
    constructor(squareX, squareY, squareSize, squareColor,squareTSpeed,squareRSpeed){ 
            this.squareX = squareX; 
            this.squareY = squareY;
            this.squareSize = squareSize;
            this.squareColor = squareColor; 
            this.squareTSpeed = squareTSpeed; 
            this.squareRSpeed = squareRSpeed; 
            
    } 
    
    translating(){ 
        push();
        translate(this.squareX,this.squareY);
        this.squareX +=random(-this.squareTSpeed,this.squareTSpeed); 
        this.squareY +=random(-this.squareTSpeed,this.squareTSpeed);
    }
    
    rotating() {
        rotate(this.angle); 
        this.angle+=this.squareRSpeed; 
    }
    
    drawing() {
        fill(this.squareColor); 
        rect(0,0,this.squareSize, this.squareSize); 
        pop();
    } 
}
let rotatingSquare;
function setup(){
    createCanvas(600,600);
    background(200);
    rectMode(CENTER);
    rotatingSquare = new RotatingSquare(300,300,30,80,5,0.2);
}
function draw(){
    rotatingSquare.translating();
    rotatingSquare.rotating();
    rotatingSquare.drawing();
}
console 命令行工具 X clear

                    
>
console