📜  p5.js |旋转()函数

📅  最后修改于: 2022-05-13 01:56:50.378000             🧑  作者: Mango

p5.js |旋转()函数

p5.js 中的rotate()函数用于将使用 p5.js 的形状或对象旋转到指定轴指定角度

句法:

rotate(angle, [axis])

参数:该函数接受上面提到的单个参数,如下所述:

  • 角度:以弧度或度数指定的旋转角度。
  • axis:要旋转的轴

下面的程序说明了 p5.js 中的 rotate()函数:
示例 1:

function setup() {
    
    // Create Canvas of given size
    createCanvas(380, 170);
}
  
function draw() {
    
    // Set the background color
    background(220);
    
    strokeWeight(12);
    
    //set strokeJoin function
    strokeJoin(ROUND);
    
    // rotation function
    rotate(PI / 10.0);
    line(20, 30, 200, 30);
    line(200, 30, 200, 100);
    line(200, 100, 20, 30);
}

输出:

示例 2:

function setup() {
    
    // Create Canvas of given size
    createCanvas(380, 170);
}
  
function draw() {
    
    // Set the background color
    background(220);
    
    strokeWeight(12);
    
    // rotation function
    rotate(PI / 7.0);
    textSize(30);
    text("GeeksForGeeks", 50, 50);
}

输出:

参考: https://p5js.org/reference/#/p5/rotate