The accelerationY system variableĀ is responsible for the acceleration of the device(tablets or mobile phones) along the y-axis. It can be used with the draw() function to accelerate the device in the y-axis of the coordinate system.
Its Value is represented as meters per second squared.
Syntax:
accelerationY
Example 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); } |
Output:
Example 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); } |
Output: