Name
text()
Description
Draws text to the screen. Displays the information specified in the first
parameter on the screen in the position specified by the additional
parameters. A default font will be used unless a font is set with the
textFont() function and a default size will be used unless a font is
set with textSize(). Change the color of the text with the
fill() function. The text displays in relation to the
textAlign() function, which gives the option to draw to the left,
right, and center of the coordinates.
The x2 and y2 parameters define a rectangular area to display
within and may only be used with string data. When these parameters are
specified, they are interpreted based on the current rectMode()
setting. Text that does not fit completely within the rectangle specified
will not be drawn to the screen.
Note that Processing now lets you call text() without first specifying
a PFont with textFont(). In that case, a generic sans-serif font will
be used instead. (See the third example above.)
Examples
size(400, 400); textSize(128); text("word", 40, 120); fill(0, 408, 612); text("word", 40, 240); fill(0, 408, 612, 204); text("word", 40, 360);
size(400, 400, P3D); textSize(128); fill(0, 408, 612, 816); text("word", 48, 180, -120); // Specify a z-axis value text("word", 48, 240); // Default depth, no z-value specified
size(400, 400); String s = "The quick brown fox jumps over the lazy dog."; fill(200); text(s, 40, 40, 280, 320); // Text wraps within text box
Syntax
text(c, x, y)
text(c, x, y, z)
text(str, x, y)
text(chars, start, stop, x, y)
text(str, x, y, z)
text(chars, start, stop, x, y, z)
text(str, x1, y1, x2, y2)
text(num, x, y)
text(num, x, y, z)
Parameters
c
(char)
the alphanumeric character to be displayedx
(float)
x-coordinate of texty
(float)
y-coordinate of textz
(float)
z-coordinate of textchars
(char[])
the alphanumeric symbols to be displayedstart
(int)
array index at which to start writing charactersstop
(int)
array index at which to stop writing charactersx1
(float)
by default, the x-coordinate of text, see rectMode() for more infoy1
(float)
by default, the y-coordinate of text, see rectMode() for more infox2
(float)
by default, the width of the text box, see rectMode() for more infoy2
(float)
by default, the height of the text box, see rectMode() for more infonum
(float, int)
the numeric value to be displayed
Return
void
Related
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.