The rotateZ() function in p5.js is used to rotate the shape or an object around the z-axis.
Syntax:
rotateZ(angle)
Parameters: This function accepts single parameter angle which stores the angle by which rotation is to be done.
Below programs illustrate the rotateZ() function in p5.js:
Example 1: This example uses rotateZ() function to rotate the an object around the z-axis.
javascript
function setup() {
createCanvas(580, 550, WEBGL);
}
function draw() {
background(220);
strokeWeight(12);
rotate(PI / 7.0);
rotateZ(millis() / 1000);
rect(3, 3, 200, 39);
ellipse(160, 160, 40, 40);
}
|
Output:
Example 2: This example uses rotateZ() function to rotate the an object around the z-axis.
javascript
function setup() {
createCanvas(500, 500, WEBGL);
}
function draw() {
background(200);
rotateZ(frameCount * 0.01);
strokeWeight(2);
fill( "green" );
cylinder(50, 100);
}
|
Output:
Reference: https://p5js.org/reference/#/p5/rotateZ
Last Updated :
17 Aug, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...