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
Related References
textToContours
Returns an array of arrays of points outlining a string of text written using the font.
textToModel
Converts text into a 3D model that can be rendered in WebGL mode.
textToPaths
Returns a flat array of path commands that describe the outlines of a string of text.
textToPoints
Returns an array of points outlining a string of text written using the font.