p5.js | textLeading() Function

The textAlign() function in p5.js is used to set the spacing, in pixels, between lines of text. This function is used in all subsequent calls to the text() function.

Syntax:

textLeading(leading)

Parameters: This function accepts single argument leading which stores the size in pixels for spacing between the lines.



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

Example 1: This example uses textAlign() function to set the spacing, in pixels, between lines of text.

filter_none

edit
close

play_arrow

link
brightness_4
code

function setup() {
  
    // Create Canvas of given size
    createCanvas(380, 170);
}
  
function draw() {
    let string = "Geeks \n For \n Geeks";
      
    // Set the background color
    background(220);
      
    // Set the text size
    textSize(16);
      
    // Set the text 
    text(string, 0, 30);
      
    // set the text leading
    textLeading(34)
      
    text(string, 100, 30);
      
    // set the text leading
    textLeading(60)
      
    text(string, 200, 30);
}

chevron_right


Output:

Example 2: This example uses textAlign() function to return the spacing, in pixels, between lines of text.

filter_none

edit
close

play_arrow

link
brightness_4
code

function setup() {
  
    // Create Canvas of given size
    createCanvas(380, 170);
}
  
function draw() {
      
    let string = "Geeks \n For \n Geeks";
      
    // Set the background color
    background(220);
      
    // Set the text size
    textSize(16);
      
    // Set the text leading
    textLeading(34)
      
    // Get the value of text leading
    var u = textLeading();
      
    // Set the stroke color
    stroke(255, 204, 0);
      
    // Display the value
    text("Value of TextLeading is : " + u, 50, 30);
}

chevron_right


Output:

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



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.



Improved By : ManasChhabra2



Article Tags :

Be the First to upvote.


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