Saturday, December 13, 2025
HomeLanguagesJavascriptp5.js accelerationY variable

p5.js accelerationY variable

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:

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32446 POSTS0 COMMENTS
Milvus
105 POSTS0 COMMENTS
Nango Kala
6814 POSTS0 COMMENTS
Nicole Veronica
11952 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12030 POSTS0 COMMENTS
Shaida Kate Naidoo
6949 POSTS0 COMMENTS
Ted Musemwa
7199 POSTS0 COMMENTS
Thapelo Manthata
6896 POSTS0 COMMENTS
Umr Jansen
6882 POSTS0 COMMENTS