Typography

Loading and displaying

create_font()

p5.create_font(name, size=10)

Create the given font at the appropriate size.

Parameters:
  • name (str) – Filename of the font file (only pil, otf and ttf fonts are supported.)
  • size (int | None) – Font size (only required when name refers to a truetype font; defaults to None)

load_font()

p5.load_font(font_name)

Loads the given font into a font object

text()

p5.text(text_string, x, y)
p5.text(text_string, x, y, z)
p5.text(text_string, position, wrap_at=None)

Draw the given text on the screen and save the image.

Parameters:
  • text_string (str) – text to display
  • x (float) – x-coordinate of text
  • y (float) – y-coordinate of text
  • z (float) – z-coordinate of text
  • position (tuple) – position of the text on the screen
  • wrap_at (int) – specifies the text wrapping column (defaults to None)
Returns:

actual text that was drawn to the image (when wrapping is not set, this is just the unmodified text_string)

Return type:

str

text_font()

p5.text_font(font, size=None)

Set current text font.

Parameters:font – PIL.ImageFont.ImageFont for Vispy, Object|String: a font loaded via loadFont(), or a String

representing a web safe font (a font that is generally available across all systems)

Text Attributes

text_align()

p5.text_align(align_x, align_y=None)

Set the alignment of drawing text

Parameters:
  • align_x (string) – “RIGHT”, “CENTER” or “LEFT”.
  • align_y (string) – “TOP”, “CENTER” or “BOTTOM”.

text_leading()

p5.text_leading(leading)

Sets the spacing between lines of text in units of pixels

Parameters:leading – the size in pixels for spacing between lines

text_size()

p5.text_size(size)

Sets the current font size

Parameters:leading – the size of the letters in units of pixels

Metrics

text_ascent()

p5.text_ascent()

Returns ascent of the current font at its current size

Returns:ascent of the current font at its current size
Return type:float

text_descent()

p5.text_descent()

Returns descent of the current font at its current size

Returns:descent of the current font at its current size
Return type:float

text_width()

p5.text_width(text)

Calculates and returns the width of any character or text string

Parameters:text_string (str) – text
Returns:width of any character or text string
Return type:int