参考 textToPoints()

textToPoints()

Returns an array of points outlining a string of text written using the font.

Each point object in the 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, fontSize, is optional. It sets the text's font size. By default, font.textToPoints() will use the current textSize().

The fifth 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.

示例

语法

textToPoints(str, x, y, [fontSize], [options])

参数

str
String:

string of text.

x
Number:

x-coordinate of the text.

y
Number:

y-coordinate of the text.

fontSize
Number:

font size. Defaults to the current textSize().

options
Object:

object with sampleFactor and simplifyThreshold properties.

Returns

Array: 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/typography/p5.Font.js and open a pull request!

相关参考