p5.js | p5.Font textBounds() Method
The textBounds() method of p5.Font in p5.js is to return a tight bounding box for the given string using the font it is used upon. This method supports only single lines.
textBounds( line, x, y, [fontSize], [options] )
Parameters: This function accepts five parameters as mentioned above and described below:
- line: It is a String which denotes the line of text for which the bounding box has to be found.
- x: It is a Number which denotes the x-position.
- y: It is a Number which denotes the y-position .
- fontSize: It is a Number which denotes the font size to be used. The default value is 12. It is an optional parameter.
- options: It is an Object which can be used to specify opentype options. Opentype fonts contain options like alignment and baseline options. The default values are “LEFT” and “alphabetic”. It is an optional parameter.
The examples below illustrates the textBounds() function in p5.js:
Online editor: https://editor.p5js.org/
Environment Setup: https://www.geeksforgeeks.org/p5-js-soundfile-object-installation-and-methods/