📜  p5.js 旋转Z 事件

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

p5.js 旋转Z 事件

p5.js中的系统变量rotationZ 负责 移动设备(智能手机和平板电脑)始终沿 z 轴旋转。可以在draw()函数中使用,连续获取当前沿z轴的旋转。如果图形 angleMode() 设置为 DEGREES,则该值将在 0 到 360 的范围内。当它设置为 RADIANS 时,该值将是 0 到 2*PI。此变量仅适用于具有内置指南针的设备。

注意:如果一起使用所有三个变量,则调用旋转的顺序很重要。需要按 Z、Y 和 X 的顺序调用它们以防止不一致。

句法:

rotationZ

示例 1:

Javascript
// Rotate the the device to see the box move
function setup() {
  createCanvas(600, 600, WEBGL);
}
  
function draw() {
  background(2);
  
  // Set the rotation to be equal to
  // the variable rotationZ
  rotateZ(radians(rotationZ));
  
  fill("blue");
  box(200, 200, 200);
}


Javascript
function setup() {
  createCanvas(600, 600, WEBGL);
}
  
function draw() {
  background(205, 105, 94);
    
  // Set the rotation to be equal to
  // the variable rotationZ
  rotateZ(radians(rotationZ));
    
  fill('green');
  cylinder(100, 200);
}


输出:

示例 2:

Javascript

function setup() {
  createCanvas(600, 600, WEBGL);
}
  
function draw() {
  background(205, 105, 94);
    
  // Set the rotation to be equal to
  // the variable rotationZ
  rotateZ(radians(rotationZ));
    
  fill('green');
  cylinder(100, 200);
}

输出: