Draws text to the canvas.
The first parameter, str
, is the text to be drawn. The second and third parameters, x
and y
, set the coordinates of the text's bottom-left corner. See textAlign() for other ways to align text.
The fourth and fifth parameters, maxWidth
and maxHeight
, are optional. They set the dimensions of the invisible rectangle containing the text. By default, they set its maximum width and height. See rectMode() for other ways to define the rectangular text box. Text will wrap to fit within the text box. Text outside of the box won't be drawn.
Text can be styled a few ways. Call the fill() function to set the text's fill color. Call stroke() and strokeWeight() to set the text's outline. Call textSize() and textFont() to set the text's size and font, respectively.
Note: WEBGL
mode only supports fonts loaded with loadFont(). Calling stroke() has no effect in WEBGL
mode.
Examples
Syntax
text(str, x, y, [maxWidth], [maxHeight])
Parameters
text to be displayed.
x-coordinate of the text box.
y-coordinate of the text box.
maximum width of the text box. See rectMode() for other options.
maximum height of the text box. See rectMode() for other options.