📜  p5.js |旋转Z()函数

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

p5.js |旋转Z()函数

p5.js 中的rotateZ()函数用于围绕 z 轴旋转形状或对象。

句法:

rotateZ(angle)

参数:此函数接受单个参数angle ,该参数存储要完成旋转的角度。
下面的程序说明了 p5.js 中的 rotateZ()函数:
示例 1:此示例使用 rotateZ()函数围绕 z 轴旋转对象。

javascript
function setup() {
 
    // Create Canvas of given size
    createCanvas(580, 550, WEBGL);
}
 
function draw() {
    // Set the background color
    background(220);
     
    // Set stroke weight
    strokeWeight(12);
     
    // Rotation function
    rotate(PI / 7.0);
     
    // Call to rotateZ function
    rotateZ(millis() / 1000);
     
    // Draw Rectangle
    rect(3, 3, 200, 39);
     
    // Draw ellipse
    ellipse(160, 160, 40, 40);
}


javascript
function setup() {
     
    // Create canvas of given size
    createCanvas(500, 500, WEBGL);
}
  
function draw() {
     
    // Set background color
    background(200);
   
    // Set property to rotate the
    // shape about the z-axis
    rotateZ(frameCount * 0.01);
     
    // Set stroke weight
    strokeWeight(2);
     
    // Set fill color
    fill("green");
     
    // Draw of height 100 and radius 50
    cylinder(50, 100);
}


输出:

示例 2:此示例使用 rotateZ()函数围绕 z 轴旋转对象。

javascript

function setup() {
     
    // Create canvas of given size
    createCanvas(500, 500, WEBGL);
}
  
function draw() {
     
    // Set background color
    background(200);
   
    // Set property to rotate the
    // shape about the z-axis
    rotateZ(frameCount * 0.01);
     
    // Set stroke weight
    strokeWeight(2);
     
    // Set fill color
    fill("green");
     
    // Draw of height 100 and radius 50
    cylinder(50, 100);
}

输出:

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