Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

p5.js | rotate() function

  • Last Updated : 22 Apr, 2019

The rotate() function in p5.js is used to rotate a shape or the object using p5.js to a specified axis over a specified angle.

Syntax:

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

rotate(angle, [axis])

Parameters: The function accepts single parameter as mentioned above and described below:

  • angle: The angle of rotation which specified in radians or degrees.
  • axis: the axis to rotate around

Below program illustrates the rotate() function in p5.js:
Example-1:






function setup() {
    
    // Create Canvas of given size
    createCanvas(380, 170);
}
  
function draw() {
    
    // Set the background color
    background(220);
    
    strokeWeight(12);
    
    //set strokeJoin function
    strokeJoin(ROUND);
    
    // rotation function
    rotate(PI / 10.0);
    line(20, 30, 200, 30);
    line(200, 30, 200, 100);
    line(200, 100, 20, 30);
}

Output:

Example-2:




function setup() {
    
    // Create Canvas of given size
    createCanvas(380, 170);
}
  
function draw() {
    
    // Set the background color
    background(220);
    
    strokeWeight(12);
    
    // rotation function
    rotate(PI / 7.0);
    textSize(30);
    text("GeeksForGeeks", 50, 50);
}

Output:

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




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!