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() {
createCanvas(650, 450, WEBGL);
}
function draw() {
background(220);
strokeWeight(12);
rotate(PI / 7.0);
rotateY(millis() / 1000);
rect(3, 3, 200, 39);
ellipse(50, 150, 40, 40);
}
|
Output:
Example 2: This example uses rotateY() function to rotate an object around the y-axis.
Javascript
function setup() {
createCanvas(500, 500, WEBGL);
}
function draw() {
background(200);
rotateY(frameCount * 0.01);
strokeWeight(2);
fill( "green" );
cylinder(50, 100);
}
|
Output:
Reference: https://p5js.org/reference/#/p5/rotateY
Last Updated :
17 Aug, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...