Saturday, October 18, 2025
HomeLanguagesJavascriptp5.js rotateY() function

p5.js rotateY() function

The rotateY() function in p5.js is used to rotate the shape or an object around the y-axis.

Syntax: 

rotateY(angle)

Parameters: This function accepts single parameter angle which stores the angle by which rotation is to be done.

Below programs illustrate the rotateY() function in p5.js:

Example 1: This example uses rotateY() function to rotate an object around the y-axis.  

Javascript




function setup() {
  
    // Create Canvas of given size
    createCanvas(650, 450, WEBGL);
}
  
function draw() {
      
    // Set the background color
    background(220);
      
    // Set stroke weight
    strokeWeight(12);
      
    // Rotation function
    rotate(PI / 7.0);
      
    // Call to rotateY function
    rotateY(millis() / 1000);
      
    // Create rectangle
    rect(3, 3, 200, 39);
      
    // Create ellipse
    ellipse(50, 150, 40, 40);
}


Output: 

Example 2: This example uses rotateY() function to rotate an object around the y-axis.  

Javascript




function setup() {
      
    // Create canvas of given size
    createCanvas(500, 500, WEBGL);
}
   
function draw() {
      
    // Set background color
    background(200);
      
    // Set property to rotate the
    // shape about the y-axis
    rotateY(frameCount * 0.01);
      
    // Set stroke weight
    strokeWeight(2);
      
    // Set fill color
    fill("green");
      
    // Draw of height 100 and radius 50
    cylinder(50, 100);
}


Output: 

Reference: https://p5js.org/reference/#/p5/rotateY
 

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!
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS