📜  p5.js 加速X 变量

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

p5.js 加速X 变量

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

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

句法:

accelerationX

示例 1:

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(accelerationX),windowWidth/2,windowHeight/2);
}


Javascript
// Move a touchscreen device to register
// Acceleration changes.
function draw() {
  createCanvas(400,400);
  background(220);
  fill('green');
    
  // Set the variable.
  ellipse(width / 4, height / 4, accelerationX);
}


输出:

示例 2:

Javascript

// Move a touchscreen device to register
// Acceleration changes.
function draw() {
  createCanvas(400,400);
  background(220);
  fill('green');
    
  // Set the variable.
  ellipse(width / 4, height / 4, accelerationX);
}

输出: