Reference textToContours()

textToContours()

Returns an array of arrays of points outlining a string of text written using the font. Each array represents a contour, so the letter O will have two outer arrays: one for the outer edge of the shape, and one for the inner edge of the hole.

Each point object in a contour array has three properties that describe the point's location and orientation, called its path angle. For example, { x: 10, y: 20, alpha: 450 }.

The first parameter, str, is a string of text. The second and third parameters, x and y, are the text's position. By default, they set the coordinates of the bounding box's bottom-left corner. See textAlign() for more ways to align text.

The fourth parameter, options, is also optional. font.textToPoints() expects an object with the following properties:

sampleFactor is the ratio of the text's path length to the number of samples. It defaults to 0.1. Higher values produce more points along the path and are more precise.

simplifyThreshold removes collinear points if it's set to a number other than 0. The value represents the threshold angle to use when determining whether two edges are collinear.

Examples

Syntax

textToContours(str, x, y, [options])

Parameters

str
String: string of text.
x
Number: x-coordinate of the text.
y
Number: y-coordinate of the text.
options
Object: object with sampleFactor and simplifyThreshold properties.

Returns

Object[][]: array of point objects, each with x, y, and alpha (path angle) properties.
Notice any errors or typos? Please let us know. Please feel free to edit src/type/p5.Font.js and open a pull request!

Related References