p5.js | textFont() Function
The textFont() function in p5.js is used to specify the font that will be used to draw text using the text() function. In the WEBGL mode, only the fonts loaded by the loadFont() method are supported.
textFont( font, size )
Parameters: This function accepts two parameters as mentioned above and described below:
- font: It is a string that specifies the name of the web safe font or a font object loaded by the loadFont() function.
- size: It is a number that specifies the size of the font to use. It is an optional parameter.
Return Value: It is an object that contains the current font.
Below examples illustrate the textFont() function in p5.js:
Example 1: This example shows the use of web safe fonts that are generally available on all systems.
Example 2: This example shows the use of a font loaded using the loadFont() function.
Online editor: https://editor.p5js.org/