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.
function setup() {
createCanvas(380, 170);
}
function draw() {
let string = "Geeks \n For \n Geeks" ;
background(220);
textSize(16);
text(string, 0, 30);
textLeading(34)
text(string, 100, 30);
textLeading(60)
text(string, 200, 30);
}
|
Output:
Example 2: This example uses textAlign() function to return the spacing, in pixels, between lines of text.
function setup() {
createCanvas(380, 170);
}
function draw() {
let string = "Geeks \n For \n Geeks" ;
background(220);
textSize(16);
textLeading(34)
var u = textLeading();
stroke(255, 204, 0);
text( "Value of TextLeading is : " + u, 50, 30);
}
|
Output:
Reference: https://p5js.org/reference/#/p5/textLeading
Last Updated :
23 Aug, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...