p5.js 加速Y变量
AccelerationY 系统变量负责设备(平板电脑或手机)沿 y 轴的加速度。它可以与 draw()函数一起使用,以在坐标系的 y 轴上加速设备。
其值表示为米每秒平方。
句法:
accelerationY
示例 1:
Javascript
// Move a touchscreen device to register
// Acceleration changes.
function setup()
{
createCanvas(400,400)
}
function draw() {
background(270);
fill('red');
textAlign(CENTER,CENTER);
textSize(50);
// Convert the acceleration into integer when
// Device is moved along y-axis.
text(int(accelerationY),windowWidth/2,windowHeight/2);
}
Javascript
// Move a touchscreen device to register
// acceleration changes.
function draw() {
createCanvas(400,400);
background(220);
fill('blue');
//Set the variable.
square(width/2, height/2, accelerationY);
}
输出:
示例 2:
Javascript
// Move a touchscreen device to register
// acceleration changes.
function draw() {
createCanvas(400,400);
background(220);
fill('blue');
//Set the variable.
square(width/2, height/2, accelerationY);
}
输出: