p5.js | Typography | shearX() Function

The shearX() function in p5.js is used to shear a shape or object around the x-axis. The object is sheared by the amount specified by the angle parameter. For proper functioning of angles should be specified in the current angleMode. The objects are always sheared around their relative position to the origin and in a clockwise direction.

Syntax:

shearX(angle)

Parameters: This function accepts single parameter angle which stores the value of angle.



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

Example 1: This example uses shearX() function to shear the object on x-axis.

filter_none

edit
close

play_arrow

link
brightness_4
code

function setup() {
  
    // Create Canvas of given size
    createCanvas(780, 650);
}
  
function draw() {
      
    // Set the background color
    background(220);
      
    // Set fill color
    fill('lightgreen');
      
    // Set stroke width
    strokeWeight(5);
      
    // Set shearX function
    shearX(PI/6);
      
    // Finally Draw the sheared rectangle
    rect(30, 30, 400, 300);
}

chevron_right


Output:

Example 2: This example uses shearX() function to shear the object on x-axis.

filter_none

edit
close

play_arrow

link
brightness_4
code

function setup() {
      
    // Create Canvas of given size
    createCanvas(780, 650);
}
  
function draw() {
      
    // Set the background color
    background(220);
      
    // Set fill color
    fill('green');
  
    // Set stroke width
    strokeWeight(5);
      
    // Set shearX function
    shearX(PI/20);
      
    // Finally Draw the sheared
    // circle of radius 80 
    circle(height/2, width/2, 80);
}

chevron_right


Output:

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



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.