📜  p5.js 加速Z 变量

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

p5.js 加速Z 变量

AccelerationZ 系统变量负责设备(平板电脑或手机)沿 Z 轴的加速度。可以在draw()函数中使用,在坐标的Z轴上加速设备。

它的值表示为米每秒平方。

句法:

accelerationZ

示例 1:

Javascript
// Move a touchscreen device to register
// acceleration changes.
function draw() {
  background(220);
  fill('blue');
    
  //Set the variable.
  square(width, height, accelerationZ);
}


Javascript
// Move a touchscreen device to register
// Acceleration changes.
function setup()
{
  createCanvas(400,400)
}
  
function draw() {
  background(0, 50);
    
  fill('green');
  textAlign(CENTER,CENTER);
  textSize(50);
    
  // Convert the acceleration into integer when
  // device is moved along x axis.
  text(int(accelerationZ),windowWidth/2,windowHeight/2);
}


输出:

示例 2:

Javascript

// Move a touchscreen device to register
// Acceleration changes.
function setup()
{
  createCanvas(400,400)
}
  
function draw() {
  background(0, 50);
    
  fill('green');
  textAlign(CENTER,CENTER);
  textSize(50);
    
  // Convert the acceleration into integer when
  // device is moved along x axis.
  text(int(accelerationZ),windowWidth/2,windowHeight/2);
}

输出:

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