p5 2.0.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{src → dist}/accessibility/color_namer.js +48 -3
- package/{src → dist}/accessibility/describe.js +12 -2
- package/{src → dist}/accessibility/gridOutput.js +2 -2
- package/dist/accessibility/index.js +60 -0
- package/{src → dist}/accessibility/outputs.js +23 -2
- package/{src → dist}/accessibility/textOutput.js +2 -2
- package/dist/app.js +120 -0
- package/{src → dist}/color/color_conversion.js +48 -10
- package/{src → dist}/color/color_spaces/hsb.js +3 -1
- package/dist/color/creating_reading.js +3 -0
- package/dist/color/index.js +13 -0
- package/dist/color/p5.Color.culori.js +1 -0
- package/dist/color/p5.Color.js +3 -0
- package/{src → dist}/color/setting.js +9 -6
- package/{src/core/constants.js → dist/constants-tYr0tCl8.js} +284 -132
- package/{src → dist}/core/States.js +3 -1
- package/dist/core/constants.js +1 -0
- package/{src → dist}/core/environment.js +12 -10
- package/{src → dist}/core/friendly_errors/browser_errors.js +1 -1
- package/{src → dist}/core/friendly_errors/fes_core.js +14 -44
- package/{src → dist}/core/friendly_errors/file_errors.js +6 -3
- package/dist/core/friendly_errors/index.js +23 -0
- package/dist/core/friendly_errors/param_validator.js +5421 -0
- package/{src → dist}/core/friendly_errors/sketch_reader.js +50 -4
- package/{src → dist}/core/friendly_errors/sketch_verifier.js +6 -6
- package/{src → dist}/core/friendly_errors/stacktrace.js +3 -5
- package/{src → dist}/core/friendly_errors/validate_params.js +50 -41
- package/{src → dist}/core/helpers.js +9 -6
- package/dist/core/init.js +105 -0
- package/dist/core/internationalization.js +302 -0
- package/dist/core/legacy.js +73 -0
- package/dist/core/main.js +44 -0
- package/dist/core/noop.js +3 -0
- package/dist/core/p5.Graphics.js +40 -0
- package/dist/core/p5.Renderer.js +11 -0
- package/dist/core/p5.Renderer2D.js +44 -0
- package/dist/core/reference.js +1 -0
- package/dist/core/rendering.js +40 -0
- package/{src → dist}/core/structure.js +3 -3
- package/{src → dist}/core/transform.js +2 -2
- package/{src/color/creating_reading.js → dist/creating_reading-Cr8L2Jnm.js} +841 -13
- package/{src → dist}/data/index.js +3 -1
- package/{src → dist}/data/local_storage.js +2 -8
- package/{src → dist}/dom/dom.js +19 -13
- package/dist/dom/index.js +18 -0
- package/{src → dist}/dom/p5.Element.js +14 -12
- package/{src → dist}/dom/p5.File.js +4 -4
- package/{src → dist}/dom/p5.MediaElement.js +10 -4
- package/{src → dist}/events/acceleration.js +26 -26
- package/{src → dist}/events/index.js +3 -1
- package/{src → dist}/events/keyboard.js +14 -12
- package/{src → dist}/events/pointer.js +16 -17
- package/dist/image/const.js +9 -0
- package/{src → dist}/image/filterRenderer2D.js +57 -37
- package/{src → dist}/image/filters.js +1 -3
- package/dist/image/image.js +40 -0
- package/dist/image/index.js +51 -0
- package/dist/image/loading_displaying.js +40 -0
- package/dist/image/p5.Image.js +11 -0
- package/{src → dist}/image/pixels.js +5 -3
- package/{src → dist}/io/csv.js +72 -70
- package/dist/io/files.js +40 -0
- package/dist/io/index.js +51 -0
- package/{src → dist}/io/p5.Table.js +6 -6
- package/{src → dist}/io/p5.TableRow.js +5 -6
- package/{src → dist}/io/p5.XML.js +2 -5
- package/{src → dist}/io/utilities.js +1 -1
- package/{src/core/p5.Renderer2D.js → dist/main-CAxvgiOV.js} +738 -57
- package/{src → dist}/math/Matrices/Matrix.js +10 -8
- package/{src → dist}/math/Matrices/MatrixInterface.js +5 -3
- package/{src → dist}/math/Matrices/MatrixNumjs.js +12 -26
- package/{src → dist}/math/calculation.js +2 -2
- package/{src → dist}/math/index.js +6 -3
- package/{src → dist}/math/math.js +3 -3
- package/{src → dist}/math/noise.js +2 -2
- package/{src → dist}/math/p5.Matrix.js +7 -4
- package/{src → dist}/math/p5.Vector.js +6 -6
- package/{src → dist}/math/random.js +2 -2
- package/{src → dist}/math/trigonometry.js +16 -15
- package/{src/image/p5.Image.js → dist/p5.Renderer-Swjl9HQO.js} +393 -22
- package/dist/rendering-B5TRR7aY.js +24960 -0
- package/{src → dist}/shape/2d_primitives.js +18 -17
- package/{src → dist}/shape/attributes.js +18 -17
- package/{src → dist}/shape/curves.js +2 -2
- package/{src → dist}/shape/custom_shapes.js +44 -64
- package/{src → dist}/shape/index.js +10 -2
- package/{src → dist}/shape/vertex.js +2 -3
- package/dist/type/index.js +25 -0
- package/{src → dist}/type/lib/Typr.js +76 -94
- package/{src → dist}/type/p5.Font.js +37 -63
- package/{src → dist}/type/textCore.js +35 -58
- package/{src → dist}/type/unicodeRanges.js +3 -1
- package/{src → dist}/utilities/conversion.js +2 -2
- package/{src → dist}/utilities/index.js +3 -1
- package/{src → dist}/utilities/time_date.js +6 -7
- package/{src → dist}/utilities/utility_functions.js +2 -2
- package/dist/webgl/3d_primitives.js +40 -0
- package/{src → dist}/webgl/GeometryBufferCache.js +3 -1
- package/{src → dist}/webgl/GeometryBuilder.js +12 -8
- package/{src → dist}/webgl/ShaderGenerator.js +79 -82
- package/{src → dist}/webgl/ShapeBuilder.js +26 -23
- package/dist/webgl/index.js +76 -0
- package/{src → dist}/webgl/interaction.js +7 -6
- package/dist/webgl/light.js +40 -0
- package/{src → dist}/webgl/loading.js +45 -12
- package/dist/webgl/material.js +40 -0
- package/dist/webgl/p5.Camera.js +40 -0
- package/{src → dist}/webgl/p5.DataArray.js +3 -5
- package/dist/webgl/p5.Framebuffer.js +40 -0
- package/{src → dist}/webgl/p5.Geometry.js +12 -15
- package/{src → dist}/webgl/p5.Quat.js +5 -4
- package/{src → dist}/webgl/p5.RenderBuffer.js +2 -3
- package/dist/webgl/p5.RendererGL.js +40 -0
- package/dist/webgl/p5.Shader.js +40 -0
- package/dist/webgl/p5.Texture.js +40 -0
- package/{src → dist}/webgl/text.js +78 -38
- package/lib/p5.esm.js +296 -194
- package/lib/p5.js +296 -194
- package/lib/p5.min.js +1 -1
- package/package.json +17 -17
- package/translations/dev.js +6 -6
- package/translations/index.js +1 -1
- package/types/accessibility/color_namer.d.ts +8 -0
- package/types/accessibility/describe.d.ts +184 -0
- package/types/accessibility/gridOutput.d.ts +8 -0
- package/types/accessibility/outputs.d.ts +235 -0
- package/types/accessibility/textOutput.d.ts +8 -0
- package/types/color/color_conversion.d.ts +47 -0
- package/types/color/creating_reading.d.ts +1348 -0
- package/types/color/p5.Color.d.ts +1070 -0
- package/types/color/setting.d.ts +2085 -0
- package/types/core/constants.d.ts +341 -0
- package/types/core/environment.d.ts +668 -0
- package/types/core/friendly_errors/fes_core.d.ts +8 -0
- package/types/core/friendly_errors/file_errors.d.ts +8 -0
- package/types/core/friendly_errors/param_validator.d.ts +30 -0
- package/types/core/friendly_errors/sketch_reader.d.ts +8 -0
- package/types/core/friendly_errors/stacktrace.d.ts +11 -0
- package/types/core/friendly_errors/validate_params.d.ts +8 -0
- package/types/core/helpers.d.ts +8 -0
- package/types/core/legacy.d.ts +8 -0
- package/types/core/main.d.ts +5996 -0
- package/types/core/p5.Graphics.d.ts +484 -0
- package/types/core/p5.Renderer.d.ts +14 -0
- package/types/core/reference.d.ts +8 -0
- package/types/core/rendering.d.ts +481 -0
- package/types/core/structure.d.ts +492 -0
- package/types/core/transform.d.ts +1638 -0
- package/types/data/local_storage.d.ts +323 -0
- package/types/dom/dom.d.ts +1295 -0
- package/types/dom/p5.Element.d.ts +2011 -0
- package/types/dom/p5.File.d.ts +13 -0
- package/types/dom/p5.MediaElement.d.ts +1249 -0
- package/types/events/acceleration.d.ts +193 -0
- package/types/events/keyboard.d.ts +499 -0
- package/types/events/pointer.d.ts +782 -0
- package/types/global.d.ts +5542 -0
- package/types/image/filterRenderer2D.d.ts +54 -0
- package/types/image/image.d.ts +326 -0
- package/types/image/loading_displaying.d.ts +580 -0
- package/types/image/p5.Image.d.ts +5882 -0
- package/types/image/pixels.d.ts +832 -0
- package/types/io/files.d.ts +1447 -0
- package/types/io/p5.Table.d.ts +1247 -0
- package/types/io/p5.TableRow.d.ts +343 -0
- package/types/io/p5.XML.d.ts +1188 -0
- package/types/math/Matrices/Matrix.d.ts +1029 -0
- package/types/math/Matrices/MatrixNumjs.d.ts +8 -0
- package/types/math/calculation.d.ts +923 -0
- package/types/math/math.d.ts +90 -0
- package/types/math/noise.d.ts +311 -0
- package/types/math/p5.Matrix.d.ts +8 -0
- package/types/math/p5.Vector.d.ts +3416 -0
- package/types/math/random.d.ts +267 -0
- package/types/math/trigonometry.d.ts +663 -0
- package/types/p5.d.ts +6663 -0
- package/types/shape/2d_primitives.d.ts +1033 -0
- package/types/shape/attributes.d.ts +466 -0
- package/types/shape/curves.d.ts +740 -0
- package/types/shape/custom_shapes.d.ts +888 -0
- package/types/shape/vertex.d.ts +1141 -0
- package/types/type/p5.Font.d.ts +575 -0
- package/types/type/textCore.d.ts +1198 -0
- package/types/utilities/conversion.d.ts +894 -0
- package/types/utilities/time_date.d.ts +295 -0
- package/types/utilities/utility_functions.d.ts +587 -0
- package/types/webgl/3d_primitives.d.ts +1432 -0
- package/types/webgl/ShaderGenerator.d.ts +8 -0
- package/types/webgl/interaction.d.ts +371 -0
- package/types/webgl/light.d.ts +1184 -0
- package/types/webgl/loading.d.ts +481 -0
- package/types/webgl/material.d.ts +2656 -0
- package/types/webgl/p5.Camera.d.ts +3023 -0
- package/types/webgl/p5.DataArray.d.ts +61 -0
- package/types/webgl/p5.Framebuffer.d.ts +760 -0
- package/types/webgl/p5.Geometry.d.ts +1191 -0
- package/types/webgl/p5.Quat.d.ts +45 -0
- package/types/webgl/p5.RendererGL.d.ts +234 -0
- package/types/webgl/p5.Shader.d.ts +660 -0
- package/types/webgl/p5.Texture.d.ts +61 -0
- package/types/webgl/text.d.ts +74 -0
- package/src/README.md +0 -27
- package/src/accessibility/index.js +0 -13
- package/src/app.js +0 -61
- package/src/color/index.js +0 -9
- package/src/color/p5.Color.culori.js +0 -66
- package/src/color/p5.Color.js +0 -851
- package/src/core/README.md +0 -91
- package/src/core/friendly_errors/index.js +0 -13
- package/src/core/friendly_errors/param_validator.js +0 -561
- package/src/core/init.js +0 -58
- package/src/core/internationalization.js +0 -195
- package/src/core/legacy.js +0 -29
- package/src/core/main.js +0 -689
- package/src/core/noop.js +0 -1
- package/src/core/p5.Graphics.js +0 -696
- package/src/core/p5.Renderer.js +0 -408
- package/src/core/reference.js +0 -2060
- package/src/core/rendering.js +0 -697
- package/src/dom/index.js +0 -11
- package/src/image/const.js +0 -6
- package/src/image/image.js +0 -731
- package/src/image/index.js +0 -15
- package/src/image/loading_displaying.js +0 -1431
- package/src/io/files.js +0 -2210
- package/src/io/index.js +0 -11
- package/src/math/README.md +0 -40
- package/src/type/index.js +0 -9
- package/src/webgl/3d_primitives.js +0 -2741
- package/src/webgl/index.js +0 -37
- package/src/webgl/light.js +0 -1851
- package/src/webgl/material.js +0 -3854
- package/src/webgl/p5.Camera.js +0 -4010
- package/src/webgl/p5.Framebuffer.js +0 -1865
- package/src/webgl/p5.RendererGL.js +0 -2867
- package/src/webgl/p5.Shader.js +0 -1505
- package/src/webgl/p5.Texture.js +0 -541
- package/src/webgl/shaders/basic.frag +0 -6
- package/src/webgl/shaders/filters/base.frag +0 -22
- package/src/webgl/shaders/filters/base.vert +0 -19
- package/src/webgl/shaders/filters/blur.frag +0 -60
- package/src/webgl/shaders/filters/default.vert +0 -18
- package/src/webgl/shaders/filters/dilate.frag +0 -39
- package/src/webgl/shaders/filters/erode.frag +0 -39
- package/src/webgl/shaders/filters/gray.frag +0 -16
- package/src/webgl/shaders/filters/invert.frag +0 -15
- package/src/webgl/shaders/filters/opaque.frag +0 -12
- package/src/webgl/shaders/filters/posterize.frag +0 -29
- package/src/webgl/shaders/filters/threshold.frag +0 -23
- package/src/webgl/shaders/font.frag +0 -216
- package/src/webgl/shaders/font.vert +0 -44
- package/src/webgl/shaders/imageLight.vert +0 -33
- package/src/webgl/shaders/imageLightDiffused.frag +0 -82
- package/src/webgl/shaders/imageLightSpecular.frag +0 -134
- package/src/webgl/shaders/light.vert +0 -37
- package/src/webgl/shaders/light_texture.frag +0 -26
- package/src/webgl/shaders/lighting.glsl +0 -227
- package/src/webgl/shaders/line.frag +0 -74
- package/src/webgl/shaders/line.vert +0 -294
- package/src/webgl/shaders/normal.frag +0 -6
- package/src/webgl/shaders/normal.vert +0 -72
- package/src/webgl/shaders/phong.frag +0 -84
- package/src/webgl/shaders/phong.vert +0 -87
- package/src/webgl/shaders/point.frag +0 -29
- package/src/webgl/shaders/point.vert +0 -19
- package/src/webgl/shaders/sphereMapping.frag +0 -26
- package/src/webgl/shaders/webgl2Compatibility.glsl +0 -34
|
@@ -0,0 +1,1198 @@
|
|
|
1
|
+
// This file is auto-generated from JSDoc documentation
|
|
2
|
+
|
|
3
|
+
import p5 from 'p5';
|
|
4
|
+
|
|
5
|
+
declare module 'p5' {
|
|
6
|
+
/**
|
|
7
|
+
* Draws text to the canvas.The first parameter, `str`, is the text to be drawn. The second and third
|
|
8
|
+
* parameters, `x` and `y`, set the coordinates of the text's bottom-left
|
|
9
|
+
* corner. See textAlign() for other ways to
|
|
10
|
+
* align text.The fourth and fifth parameters, `maxWidth` and `maxHeight`, are optional.
|
|
11
|
+
* They set the dimensions of the invisible rectangle containing the text. By
|
|
12
|
+
* default, they set its maximum width and height. See
|
|
13
|
+
* rectMode() for other ways to define the
|
|
14
|
+
* rectangular text box. Text will wrap to fit within the text box. Text
|
|
15
|
+
* outside of the box won't be drawn.Text can be styled a few ways. Call the fill()
|
|
16
|
+
* function to set the text's fill color. Call
|
|
17
|
+
* stroke() and
|
|
18
|
+
* strokeWeight() to set the text's outline.
|
|
19
|
+
* Call textSize() and
|
|
20
|
+
* textFont() to set the text's size and font,
|
|
21
|
+
* respectively.Note: `WEBGL` mode only supports fonts loaded with
|
|
22
|
+
* loadFont(). Calling
|
|
23
|
+
* stroke() has no effect in `WEBGL` mode.
|
|
24
|
+
*
|
|
25
|
+
* @param text to be displayed.
|
|
26
|
+
* @param x-coordinate of the text box.
|
|
27
|
+
* @param y-coordinate of the text box.
|
|
28
|
+
* @param maximum width of the text box. See
|
|
29
|
+
* <a href="#/p5/rectMode">rectMode()</a> for
|
|
30
|
+
* other options.
|
|
31
|
+
* @param maximum height of the text box. See
|
|
32
|
+
* <a href="#/p5/rectMode">rectMode()</a> for
|
|
33
|
+
* other options.
|
|
34
|
+
* @for p5
|
|
35
|
+
* @example <div>
|
|
36
|
+
* <code>
|
|
37
|
+
* function setup() {
|
|
38
|
+
* createCanvas(100, 100);
|
|
39
|
+
* background(200);
|
|
40
|
+
* text('hi', 50, 50);
|
|
41
|
+
*
|
|
42
|
+
* describe('The text "hi" written in black in the middle of a gray square.');
|
|
43
|
+
* }
|
|
44
|
+
* </code>
|
|
45
|
+
* </div>
|
|
46
|
+
*
|
|
47
|
+
* <div>
|
|
48
|
+
* <code>
|
|
49
|
+
* function setup() {
|
|
50
|
+
* createCanvas(100, 100);
|
|
51
|
+
* background('skyblue');
|
|
52
|
+
* textSize(100);
|
|
53
|
+
* text('🌈', 0, 100);
|
|
54
|
+
*
|
|
55
|
+
* describe('A rainbow in a blue sky.');
|
|
56
|
+
* }
|
|
57
|
+
* </code>
|
|
58
|
+
* </div>
|
|
59
|
+
* @example <div>
|
|
60
|
+
* <code>
|
|
61
|
+
* function setup() {
|
|
62
|
+
* createCanvas(100, 100);
|
|
63
|
+
* textSize(32);
|
|
64
|
+
* fill(255);
|
|
65
|
+
* stroke(0);
|
|
66
|
+
* strokeWeight(4);
|
|
67
|
+
* text('hi', 50, 50);
|
|
68
|
+
*
|
|
69
|
+
* describe('The text "hi" written in white with a black outline.');
|
|
70
|
+
* }
|
|
71
|
+
* </code>
|
|
72
|
+
* </div>
|
|
73
|
+
* @example <div>
|
|
74
|
+
* <code>
|
|
75
|
+
* function setup() {
|
|
76
|
+
* createCanvas(100, 100);
|
|
77
|
+
* background('black');
|
|
78
|
+
* textSize(22);
|
|
79
|
+
* fill('yellow');
|
|
80
|
+
* text('rainbows', 6, 20);
|
|
81
|
+
* fill('cornflowerblue');
|
|
82
|
+
* text('rainbows', 6, 45);
|
|
83
|
+
* fill('tomato');
|
|
84
|
+
* text('rainbows', 6, 70);
|
|
85
|
+
* fill('limegreen');
|
|
86
|
+
* text('rainbows', 6, 95);
|
|
87
|
+
*
|
|
88
|
+
* describe('The text "rainbows" written on several lines, each in a different color.');
|
|
89
|
+
* }
|
|
90
|
+
* </code>
|
|
91
|
+
* </div>
|
|
92
|
+
* @example <div>
|
|
93
|
+
* <code>
|
|
94
|
+
* function setup() {
|
|
95
|
+
* createCanvas(100, 100);
|
|
96
|
+
* background(200);
|
|
97
|
+
* let s = 'The quick brown fox jumps over the lazy dog.';
|
|
98
|
+
* text(s, 10, 10, 70, 80);
|
|
99
|
+
*
|
|
100
|
+
* describe('The sample text "The quick brown fox..." written in black across several lines.');
|
|
101
|
+
* }
|
|
102
|
+
* </code>
|
|
103
|
+
* </div>
|
|
104
|
+
* @example <div>
|
|
105
|
+
* <code>
|
|
106
|
+
* function setup() {
|
|
107
|
+
* createCanvas(100, 100);
|
|
108
|
+
* background(200);
|
|
109
|
+
* rectMode(CENTER);
|
|
110
|
+
* let s = 'The quick brown fox jumps over the lazy dog.';
|
|
111
|
+
* text(s, 50, 50, 70, 80);
|
|
112
|
+
*
|
|
113
|
+
* describe('The sample text "The quick brown fox..." written in black across several lines.');
|
|
114
|
+
* }
|
|
115
|
+
* </code>
|
|
116
|
+
* </div>
|
|
117
|
+
* @example <div modernizr='webgl'>
|
|
118
|
+
* <code>
|
|
119
|
+
* let font;
|
|
120
|
+
*
|
|
121
|
+
* async function setup() {
|
|
122
|
+
* createCanvas(100, 100, WEBGL);
|
|
123
|
+
* font = await loadFont('assets/inconsolata.otf');
|
|
124
|
+
* textFont(font);
|
|
125
|
+
* textSize(32);
|
|
126
|
+
* textAlign(CENTER, CENTER);
|
|
127
|
+
* }
|
|
128
|
+
*
|
|
129
|
+
* function draw() {
|
|
130
|
+
* background(200);
|
|
131
|
+
* rotateY(frameCount / 30);
|
|
132
|
+
* text('p5*js', 0, 0);
|
|
133
|
+
*
|
|
134
|
+
* describe('The text "p5*js" written in white and spinning in 3D.');
|
|
135
|
+
* }
|
|
136
|
+
* </code>
|
|
137
|
+
* </div>
|
|
138
|
+
*/
|
|
139
|
+
function text(str: string | object | Array | number | boolean, x: number, y: number, maxWidth?: number, maxHeight?: number): void;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Sets the way text is aligned when text() is called.By default, calling `text('hi', 10, 20)` places the bottom-left corner of
|
|
143
|
+
* the text's bounding box at (10, 20).The first parameter, `horizAlign`, changes the way
|
|
144
|
+
* text() interprets x-coordinates. By default, the
|
|
145
|
+
* x-coordinate sets the left edge of the bounding box. `textAlign()` accepts
|
|
146
|
+
* the following values for `horizAlign`: `LEFT`, `CENTER`, or `RIGHT`.The second parameter, `vertAlign`, is optional. It changes the way
|
|
147
|
+
* text() interprets y-coordinates. By default, the
|
|
148
|
+
* y-coordinate sets the bottom edge of the bounding box. `textAlign()`
|
|
149
|
+
* accepts the following values for `vertAlign`: `TOP`, `BOTTOM`, `CENTER`,
|
|
150
|
+
* or `BASELINE`.
|
|
151
|
+
*
|
|
152
|
+
* @for p5
|
|
153
|
+
* @param horizontal alignment
|
|
154
|
+
* @param vertical alignment
|
|
155
|
+
* @example <div>
|
|
156
|
+
* <code>
|
|
157
|
+
* function setup() {
|
|
158
|
+
* createCanvas(100, 100);
|
|
159
|
+
*
|
|
160
|
+
* background(200);
|
|
161
|
+
*
|
|
162
|
+
* // Draw a vertical line.
|
|
163
|
+
* strokeWeight(0.5);
|
|
164
|
+
* line(50, 0, 50, 100);
|
|
165
|
+
*
|
|
166
|
+
* // Top line.
|
|
167
|
+
* textSize(16);
|
|
168
|
+
* textAlign(RIGHT);
|
|
169
|
+
* text('ABCD', 50, 30);
|
|
170
|
+
*
|
|
171
|
+
* // Middle line.
|
|
172
|
+
* textAlign(CENTER);
|
|
173
|
+
* text('EFGH', 50, 50);
|
|
174
|
+
*
|
|
175
|
+
* // Bottom line.
|
|
176
|
+
* textAlign(LEFT);
|
|
177
|
+
* text('IJKL', 50, 70);
|
|
178
|
+
*
|
|
179
|
+
* describe('The letters ABCD displayed at top-left, EFGH at center, and IJKL at bottom-right. A vertical line divides the canvas in half.');
|
|
180
|
+
* }
|
|
181
|
+
* </code>
|
|
182
|
+
* </div>
|
|
183
|
+
* @example <div>
|
|
184
|
+
* <code>
|
|
185
|
+
* function setup() {
|
|
186
|
+
* createCanvas(100, 100);
|
|
187
|
+
*
|
|
188
|
+
* background(200);
|
|
189
|
+
*
|
|
190
|
+
* strokeWeight(0.5);
|
|
191
|
+
*
|
|
192
|
+
* // First line.
|
|
193
|
+
* line(0, 12, width, 12);
|
|
194
|
+
* textAlign(CENTER, TOP);
|
|
195
|
+
* text('TOP', 50, 12);
|
|
196
|
+
*
|
|
197
|
+
* // Second line.
|
|
198
|
+
* line(0, 37, width, 37);
|
|
199
|
+
* textAlign(CENTER, CENTER);
|
|
200
|
+
* text('CENTER', 50, 37);
|
|
201
|
+
*
|
|
202
|
+
* // Third line.
|
|
203
|
+
* line(0, 62, width, 62);
|
|
204
|
+
* textAlign(CENTER, BASELINE);
|
|
205
|
+
* text('BASELINE', 50, 62);
|
|
206
|
+
*
|
|
207
|
+
* // Fourth line.
|
|
208
|
+
* line(0, 97, width, 97);
|
|
209
|
+
* textAlign(CENTER, BOTTOM);
|
|
210
|
+
* text('BOTTOM', 50, 97);
|
|
211
|
+
*
|
|
212
|
+
* describe('The words "TOP", "CENTER", "BASELINE", and "BOTTOM" each drawn relative to a horizontal line. Their positions demonstrate different vertical alignments.');
|
|
213
|
+
* }
|
|
214
|
+
* </code>
|
|
215
|
+
* </div>
|
|
216
|
+
*/
|
|
217
|
+
function textAlign(horizAlign: LEFT | CENTER | RIGHT, vertAlign?: TOP | BOTTOM | CENTER | BASELINE): void;
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Returns the ascent of the text.The `textAscent()` function calculates the distance from the baseline to the
|
|
221
|
+
* highest point of the current font. This value represents the ascent, which is essential
|
|
222
|
+
* for determining the overall height of the text along with `textDescent()`. If
|
|
223
|
+
* a text string is provided as an argument, the ascent is calculated based on that specific
|
|
224
|
+
* string; otherwise, the ascent of the current font is returned.
|
|
225
|
+
*
|
|
226
|
+
* @for p5
|
|
227
|
+
* @param (Optional) The text string for which to calculate the ascent.
|
|
228
|
+
* If omitted, the function returns the ascent for the current font.
|
|
229
|
+
* @returns The ascent value in pixels.
|
|
230
|
+
* @example <div>
|
|
231
|
+
* <code>
|
|
232
|
+
* function setup() {
|
|
233
|
+
* createCanvas(400, 300);
|
|
234
|
+
* background(220);
|
|
235
|
+
*
|
|
236
|
+
* textSize(48);
|
|
237
|
+
* textAlign(LEFT, BASELINE);
|
|
238
|
+
* textFont('Georgia');
|
|
239
|
+
*
|
|
240
|
+
* let s = "Hello, p5.js!";
|
|
241
|
+
* let x = 50, y = 150;
|
|
242
|
+
*
|
|
243
|
+
* fill(0);
|
|
244
|
+
* text(s, x, y);
|
|
245
|
+
*
|
|
246
|
+
* // Get the ascent of the current font
|
|
247
|
+
* let asc = textAscent();
|
|
248
|
+
*
|
|
249
|
+
* // Draw a red line at the baseline and a blue line at the ascent position
|
|
250
|
+
* stroke('red');
|
|
251
|
+
* line(x, y, x + 200, y); // Baseline
|
|
252
|
+
* stroke('blue');
|
|
253
|
+
* line(x, y - asc, x + 200, y - asc); // Ascent (top of text)
|
|
254
|
+
*
|
|
255
|
+
* noStroke();
|
|
256
|
+
* fill(0);
|
|
257
|
+
* textSize(16);
|
|
258
|
+
* text("textAscent: " + asc.toFixed(2) + " pixels", x, y - asc - 10);
|
|
259
|
+
* }
|
|
260
|
+
* </code>
|
|
261
|
+
* </div>
|
|
262
|
+
* @example <div>
|
|
263
|
+
* <code>
|
|
264
|
+
* let font;
|
|
265
|
+
*
|
|
266
|
+
* async function setup() {
|
|
267
|
+
* font = await loadFont('assets/inconsolata.otf');
|
|
268
|
+
*
|
|
269
|
+
* createCanvas(100, 100);
|
|
270
|
+
*
|
|
271
|
+
* background(200);
|
|
272
|
+
*
|
|
273
|
+
* // Style the text.
|
|
274
|
+
* textFont(font);
|
|
275
|
+
*
|
|
276
|
+
* // Different for each font.
|
|
277
|
+
* let fontScale = 0.8;
|
|
278
|
+
*
|
|
279
|
+
* let baseY = 75;
|
|
280
|
+
* strokeWeight(0.5);
|
|
281
|
+
*
|
|
282
|
+
* // Draw small text.
|
|
283
|
+
* textSize(24);
|
|
284
|
+
* text('dp', 0, baseY);
|
|
285
|
+
*
|
|
286
|
+
* // Draw baseline and ascent.
|
|
287
|
+
* let a = textAscent() * fontScale;
|
|
288
|
+
* line(0, baseY, 23, baseY);
|
|
289
|
+
* line(23, baseY - a, 23, baseY);
|
|
290
|
+
*
|
|
291
|
+
* // Draw large text.
|
|
292
|
+
* textSize(48);
|
|
293
|
+
* text('dp', 45, baseY);
|
|
294
|
+
*
|
|
295
|
+
* // Draw baseline and ascent.
|
|
296
|
+
* a = textAscent() * fontScale;
|
|
297
|
+
* line(45, baseY, 91, baseY);
|
|
298
|
+
* line(91, baseY - a, 91, baseY);
|
|
299
|
+
*
|
|
300
|
+
* describe('The letters "dp" written twice in different sizes. Each version has a horizontal baseline. A vertical line extends upward from each baseline to the top of the "d".');
|
|
301
|
+
* }
|
|
302
|
+
* </code>
|
|
303
|
+
* </div>
|
|
304
|
+
*/
|
|
305
|
+
function textAscent(txt?: string): number;
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Returns the descent of the text.The `textDescent()` function calculates the distance from the baseline to the
|
|
309
|
+
* lowest point of the current font. This value represents the descent, which, when combined
|
|
310
|
+
* with the ascent (from `textAscent()`), determines the overall vertical span of the text.
|
|
311
|
+
* If a text string is provided as an argument, the descent is calculated based on that specific string;
|
|
312
|
+
* otherwise, the descent of the current font is returned.
|
|
313
|
+
*
|
|
314
|
+
* @for p5
|
|
315
|
+
* @param (Optional) The text string for which to calculate the descent.
|
|
316
|
+
* If omitted, the function returns the descent for the current font.
|
|
317
|
+
* @returns The descent value in pixels.
|
|
318
|
+
* @example <div>
|
|
319
|
+
* <code>
|
|
320
|
+
* function setup() {
|
|
321
|
+
* createCanvas(400, 300);
|
|
322
|
+
* background(220);
|
|
323
|
+
*
|
|
324
|
+
* textSize(48);
|
|
325
|
+
* textAlign(LEFT, BASELINE);
|
|
326
|
+
* textFont('Georgia');
|
|
327
|
+
*
|
|
328
|
+
* let s = "Hello, p5.js!";
|
|
329
|
+
* let x = 50, y = 150;
|
|
330
|
+
*
|
|
331
|
+
* fill(0);
|
|
332
|
+
* text(s, x, y);
|
|
333
|
+
*
|
|
334
|
+
* // Get the descent of the current font
|
|
335
|
+
* let desc = textDescent();
|
|
336
|
+
*
|
|
337
|
+
* // Draw a red line at the baseline and a blue line at the bottom of the text
|
|
338
|
+
* stroke('red');
|
|
339
|
+
* line(x, y, x + 200, y); // Baseline
|
|
340
|
+
* stroke('blue');
|
|
341
|
+
* line(x, y + desc, x + 200, y + desc); // Descent (bottom of text)
|
|
342
|
+
*
|
|
343
|
+
* noStroke();
|
|
344
|
+
* fill(0);
|
|
345
|
+
* textSize(16);
|
|
346
|
+
* text("textDescent: " + desc.toFixed(2) + " pixels", x, y + desc + 20);
|
|
347
|
+
* }
|
|
348
|
+
* </code>
|
|
349
|
+
* </div>
|
|
350
|
+
* @example <div>
|
|
351
|
+
* <code>
|
|
352
|
+
* let font;
|
|
353
|
+
*
|
|
354
|
+
* async function setup() {
|
|
355
|
+
* font = await loadFont('assets/inconsolata.otf');
|
|
356
|
+
*
|
|
357
|
+
* createCanvas(100, 100);
|
|
358
|
+
*
|
|
359
|
+
* background(200);
|
|
360
|
+
*
|
|
361
|
+
* // Style the font.
|
|
362
|
+
* textFont(font);
|
|
363
|
+
*
|
|
364
|
+
* // Different for each font.
|
|
365
|
+
* let fontScale = 0.9;
|
|
366
|
+
*
|
|
367
|
+
* let baseY = 75;
|
|
368
|
+
* strokeWeight(0.5);
|
|
369
|
+
*
|
|
370
|
+
* // Draw small text.
|
|
371
|
+
* textSize(24);
|
|
372
|
+
* text('dp', 0, baseY);
|
|
373
|
+
*
|
|
374
|
+
* // Draw baseline and descent.
|
|
375
|
+
* let d = textDescent() * fontScale;
|
|
376
|
+
* line(0, baseY, 23, baseY);
|
|
377
|
+
* line(23, baseY, 23, baseY + d);
|
|
378
|
+
*
|
|
379
|
+
* // Draw large text.
|
|
380
|
+
* textSize(48);
|
|
381
|
+
* text('dp', 45, baseY);
|
|
382
|
+
*
|
|
383
|
+
* // Draw baseline and descent.
|
|
384
|
+
* d = textDescent() * fontScale;
|
|
385
|
+
* line(45, baseY, 91, baseY);
|
|
386
|
+
* line(91, baseY, 91, baseY + d);
|
|
387
|
+
*
|
|
388
|
+
* describe('The letters "dp" written twice in different sizes. Each version has a horizontal baseline. A vertical line extends downward from each baseline to the bottom of the "p".');
|
|
389
|
+
* }
|
|
390
|
+
* </code>
|
|
391
|
+
* </div>
|
|
392
|
+
*/
|
|
393
|
+
function textDescent(txt?: string): number;
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* Sets the spacing between lines of text when
|
|
397
|
+
* text() is called.Note: Spacing is measured in pixels.Calling `textLeading()` without an argument returns the current spacing.
|
|
398
|
+
*
|
|
399
|
+
* @for p5
|
|
400
|
+
* @param The new text leading to apply, in pixels
|
|
401
|
+
* @returns If no arguments are provided, the current text leading
|
|
402
|
+
* @example <div>
|
|
403
|
+
* <code>
|
|
404
|
+
* function setup() {
|
|
405
|
+
* createCanvas(100, 100);
|
|
406
|
+
*
|
|
407
|
+
* background(200);
|
|
408
|
+
*
|
|
409
|
+
* // "\n" starts a new line of text.
|
|
410
|
+
* let lines = 'one\ntwo';
|
|
411
|
+
*
|
|
412
|
+
* // Left.
|
|
413
|
+
* text(lines, 10, 25);
|
|
414
|
+
*
|
|
415
|
+
* // Right.
|
|
416
|
+
* textLeading(30);
|
|
417
|
+
* text(lines, 70, 25);
|
|
418
|
+
*
|
|
419
|
+
* describe('The words "one" and "two" written on separate lines twice. The words on the left have less vertical spacing than the words on the right.');
|
|
420
|
+
* }
|
|
421
|
+
* </code>
|
|
422
|
+
* </div>
|
|
423
|
+
*/
|
|
424
|
+
function textLeading(leading: number): number;
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* Sets the font used by the text() function.The first parameter, `font`, sets the font. `textFont()` recognizes either
|
|
428
|
+
* a p5.Font object or a string with the name of a
|
|
429
|
+
* system font. For example, `'Courier New'`.The second parameter, `size`, is optional. It sets the font size in pixels.
|
|
430
|
+
* This has the same effect as calling textSize().Note: `WEBGL` mode only supports fonts loaded with
|
|
431
|
+
* loadFont().
|
|
432
|
+
*
|
|
433
|
+
* @param The font to apply
|
|
434
|
+
* @param An optional text size to apply.
|
|
435
|
+
* @for p5
|
|
436
|
+
* @example <div>
|
|
437
|
+
* <code>
|
|
438
|
+
* function setup() {
|
|
439
|
+
* createCanvas(100, 100);
|
|
440
|
+
* background(200);
|
|
441
|
+
* textFont('Courier New');
|
|
442
|
+
* textSize(24);
|
|
443
|
+
* text('hi', 35, 55);
|
|
444
|
+
*
|
|
445
|
+
* describe('The text "hi" written in a black, monospace font on a gray background.');
|
|
446
|
+
* }
|
|
447
|
+
* </code>
|
|
448
|
+
* </div>
|
|
449
|
+
* @example <div>
|
|
450
|
+
* <code>
|
|
451
|
+
* function setup() {
|
|
452
|
+
* createCanvas(100, 100);
|
|
453
|
+
* background('black');
|
|
454
|
+
* fill('palegreen');
|
|
455
|
+
* textFont('Courier New', 10);
|
|
456
|
+
* text('You turn to the left and see a door. Do you enter?', 5, 5, 90, 90);
|
|
457
|
+
* text('>', 5, 70);
|
|
458
|
+
*
|
|
459
|
+
* describe('A text prompt from a game is written in a green, monospace font on a black background.');
|
|
460
|
+
* }
|
|
461
|
+
* </code>
|
|
462
|
+
* </div>
|
|
463
|
+
* @example <div>
|
|
464
|
+
* <code>
|
|
465
|
+
* function setup() {
|
|
466
|
+
* createCanvas(100, 100);
|
|
467
|
+
* background(200);
|
|
468
|
+
* textFont('Verdana');
|
|
469
|
+
* let currentFont = textFont();
|
|
470
|
+
* text(currentFont, 25, 50);
|
|
471
|
+
*
|
|
472
|
+
* describe('The text "Verdana" written in a black, sans-serif font on a gray background.');
|
|
473
|
+
* }
|
|
474
|
+
* </code>
|
|
475
|
+
* </div>
|
|
476
|
+
* @example <div>
|
|
477
|
+
* <code>
|
|
478
|
+
* let fontRegular;
|
|
479
|
+
* let fontItalic;
|
|
480
|
+
* let fontBold;
|
|
481
|
+
*
|
|
482
|
+
* async function setup() {
|
|
483
|
+
* createCanvas(100, 100);
|
|
484
|
+
* fontRegular = await loadFont('assets/Regular.otf');
|
|
485
|
+
* fontItalic = await loadFont('assets/Italic.ttf');
|
|
486
|
+
* fontBold = await loadFont('assets/Bold.ttf');
|
|
487
|
+
*
|
|
488
|
+
* background(200);
|
|
489
|
+
* textFont(fontRegular);
|
|
490
|
+
* text('I am Normal', 10, 30);
|
|
491
|
+
* textFont(fontItalic);
|
|
492
|
+
* text('I am Italic', 10, 50);
|
|
493
|
+
* textFont(fontBold);
|
|
494
|
+
* text('I am Bold', 10, 70);
|
|
495
|
+
*
|
|
496
|
+
* describe('The statements "I am Normal", "I am Italic", and "I am Bold" written in black on separate lines. The statements have normal, italic, and bold fonts, respectively.');
|
|
497
|
+
* }
|
|
498
|
+
* </code>
|
|
499
|
+
* </div>
|
|
500
|
+
*/
|
|
501
|
+
function textFont(font: p5.Font | string | object, size?: number): void;
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Sets or gets the current text size.The `textSize()` function is used to specify the size of the text
|
|
505
|
+
* that will be rendered on the canvas. When called with an argument, it sets the
|
|
506
|
+
* text size to the specified value (which can be a number representing pixels or a
|
|
507
|
+
* CSS-style string, e.g., '32px', '2em'). When called without an argument, it
|
|
508
|
+
* returns the current text size in pixels.
|
|
509
|
+
*
|
|
510
|
+
* @for p5
|
|
511
|
+
* @param The size to set for the text.
|
|
512
|
+
* @returns If no arguments are provided, the current text size in pixels.
|
|
513
|
+
* @example <div>
|
|
514
|
+
* <code>
|
|
515
|
+
* function setup() {
|
|
516
|
+
* createCanvas(600, 200);
|
|
517
|
+
* background(240);
|
|
518
|
+
*
|
|
519
|
+
* // Set the text size to 48 pixels
|
|
520
|
+
* textSize(48);
|
|
521
|
+
* textAlign(CENTER, CENTER);
|
|
522
|
+
* textFont("Georgia");
|
|
523
|
+
*
|
|
524
|
+
* // Draw text using the current text size
|
|
525
|
+
* fill(0);
|
|
526
|
+
* text("Hello, p5.js!", width / 2, height / 2);
|
|
527
|
+
*
|
|
528
|
+
* // Retrieve and display the current text size
|
|
529
|
+
* let currentSize = textSize();
|
|
530
|
+
* fill(50);
|
|
531
|
+
* textSize(16);
|
|
532
|
+
* text("Current text size: " + currentSize, width / 2, height - 20);
|
|
533
|
+
* }
|
|
534
|
+
* </code>
|
|
535
|
+
* </div>
|
|
536
|
+
* @example <div>
|
|
537
|
+
* <code>
|
|
538
|
+
* function setup() {
|
|
539
|
+
* createCanvas(100, 100);
|
|
540
|
+
*
|
|
541
|
+
* background(200);
|
|
542
|
+
*
|
|
543
|
+
* // Top.
|
|
544
|
+
* textSize(12);
|
|
545
|
+
* text('Font Size 12', 10, 30);
|
|
546
|
+
*
|
|
547
|
+
* // Middle.
|
|
548
|
+
* textSize(14);
|
|
549
|
+
* text('Font Size 14', 10, 60);
|
|
550
|
+
*
|
|
551
|
+
* // Bottom.
|
|
552
|
+
* textSize(16);
|
|
553
|
+
* text('Font Size 16', 10, 90);
|
|
554
|
+
*
|
|
555
|
+
* describe('The text "Font Size 12" drawn small, "Font Size 14" drawn medium, and "Font Size 16" drawn large.');
|
|
556
|
+
* }
|
|
557
|
+
* </code>
|
|
558
|
+
* </div>
|
|
559
|
+
*/
|
|
560
|
+
function textSize(size: number): number;
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* @for p5
|
|
564
|
+
* @returns The current text size in pixels.
|
|
565
|
+
*/
|
|
566
|
+
function textSize(): number;
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* Sets the style for system fonts when
|
|
570
|
+
* text() is called.The parameter, `style`, can be either `NORMAL`, `ITALIC`, `BOLD`, or
|
|
571
|
+
* `BOLDITALIC`.`textStyle()` may be overridden by CSS styling. This function doesn't
|
|
572
|
+
* affect fonts loaded with loadFont().
|
|
573
|
+
*
|
|
574
|
+
* @for p5
|
|
575
|
+
* @param The style to use
|
|
576
|
+
* @returns If no arguments are provided, the current style
|
|
577
|
+
* @example <div>
|
|
578
|
+
* <code>
|
|
579
|
+
* function setup() {
|
|
580
|
+
* createCanvas(100, 100);
|
|
581
|
+
*
|
|
582
|
+
* background(200);
|
|
583
|
+
*
|
|
584
|
+
* // Style the text.
|
|
585
|
+
* textSize(12);
|
|
586
|
+
* textAlign(CENTER);
|
|
587
|
+
*
|
|
588
|
+
* // First row.
|
|
589
|
+
* textStyle(NORMAL);
|
|
590
|
+
* text('Normal', 50, 15);
|
|
591
|
+
*
|
|
592
|
+
* // Second row.
|
|
593
|
+
* textStyle(ITALIC);
|
|
594
|
+
* text('Italic', 50, 40);
|
|
595
|
+
*
|
|
596
|
+
* // Third row.
|
|
597
|
+
* textStyle(BOLD);
|
|
598
|
+
* text('Bold', 50, 65);
|
|
599
|
+
*
|
|
600
|
+
* // Fourth row.
|
|
601
|
+
* textStyle(BOLDITALIC);
|
|
602
|
+
* text('Bold Italic', 50, 90);
|
|
603
|
+
*
|
|
604
|
+
* describe('The words "Normal" displayed normally, "Italic" in italic, "Bold" in bold, and "Bold Italic" in bold italics.');
|
|
605
|
+
* }
|
|
606
|
+
* </code>
|
|
607
|
+
* </div>
|
|
608
|
+
*/
|
|
609
|
+
function textStyle(style: NORMAL | ITALIC | BOLD | BOLDITALIC): NORMAL | ITALIC | BOLD | BOLDITALIC;
|
|
610
|
+
|
|
611
|
+
/**
|
|
612
|
+
* @for p5
|
|
613
|
+
*/
|
|
614
|
+
function textStyle(): NORMAL | BOLD | ITALIC | BOLDITALIC;
|
|
615
|
+
|
|
616
|
+
/**
|
|
617
|
+
* Calculates the width of the given text string in pixels.The `textWidth()` function processes the provided text string to determine its tight bounding box
|
|
618
|
+
* based on the current text properties such as font, textSize, and textStyle. Internally, it splits
|
|
619
|
+
* the text into individual lines (if line breaks are present) and computes the bounding box for each
|
|
620
|
+
* line using the renderer’s measurement functions. The final width is determined as the maximum width
|
|
621
|
+
* among all these lines.For example, if the text contains multiple lines due to wrapping or explicit line breaks, textWidth()
|
|
622
|
+
* will return the width of the longest line.
|
|
623
|
+
*
|
|
624
|
+
* @for p5
|
|
625
|
+
* @param The text to measure
|
|
626
|
+
* @returns The width of the text
|
|
627
|
+
* @example <div>
|
|
628
|
+
* <code>
|
|
629
|
+
* function setup() {
|
|
630
|
+
* createCanvas(200, 200);
|
|
631
|
+
* background(220);
|
|
632
|
+
*
|
|
633
|
+
* // Set text size and alignment
|
|
634
|
+
* textSize(48);
|
|
635
|
+
* textAlign(LEFT, TOP);
|
|
636
|
+
*
|
|
637
|
+
* let myText = "Hello";
|
|
638
|
+
*
|
|
639
|
+
* // Calculate the width of the text
|
|
640
|
+
* let tw = textWidth(myText);
|
|
641
|
+
*
|
|
642
|
+
* // Draw the text on the canvas
|
|
643
|
+
* fill(0);
|
|
644
|
+
* text(myText, 50, 50);
|
|
645
|
+
*
|
|
646
|
+
* // Display the text width below
|
|
647
|
+
* noStroke();
|
|
648
|
+
* fill(0);
|
|
649
|
+
* textSize(20);
|
|
650
|
+
* text("Text width: " + tw, 10, 150);
|
|
651
|
+
* }
|
|
652
|
+
* </code>
|
|
653
|
+
* </div>
|
|
654
|
+
* @example <div>
|
|
655
|
+
* <code>
|
|
656
|
+
* function setup() {
|
|
657
|
+
* createCanvas(100, 100);
|
|
658
|
+
*
|
|
659
|
+
* background(200);
|
|
660
|
+
*
|
|
661
|
+
* // Style the text.
|
|
662
|
+
* textSize(28);
|
|
663
|
+
* strokeWeight(0.5);
|
|
664
|
+
*
|
|
665
|
+
* // Calculate the text width.
|
|
666
|
+
* let s = 'yoyo';
|
|
667
|
+
* let w = textWidth(s);
|
|
668
|
+
*
|
|
669
|
+
* // Display the text.
|
|
670
|
+
* text(s, 22, 55);
|
|
671
|
+
*
|
|
672
|
+
* // Underline the text.
|
|
673
|
+
* line(22, 55, 22 + w, 55);
|
|
674
|
+
*
|
|
675
|
+
* describe('The word "yoyo" underlined.');
|
|
676
|
+
* }
|
|
677
|
+
* </code>
|
|
678
|
+
* </div>
|
|
679
|
+
* @example <div>
|
|
680
|
+
* <code>
|
|
681
|
+
* function setup() {
|
|
682
|
+
* createCanvas(100, 100);
|
|
683
|
+
*
|
|
684
|
+
* background(200);
|
|
685
|
+
*
|
|
686
|
+
* // Style the text.
|
|
687
|
+
* textSize(28);
|
|
688
|
+
* strokeWeight(0.5);
|
|
689
|
+
*
|
|
690
|
+
* // Calculate the text width.
|
|
691
|
+
* // "\n" starts a new line.
|
|
692
|
+
* let s = 'yo\nyo';
|
|
693
|
+
* let w = textWidth(s);
|
|
694
|
+
*
|
|
695
|
+
* // Display the text.
|
|
696
|
+
* text(s, 22, 55);
|
|
697
|
+
*
|
|
698
|
+
* // Underline the text.
|
|
699
|
+
* line(22, 55, 22 + w, 55);
|
|
700
|
+
*
|
|
701
|
+
* describe('The word "yo" written twice, one copy beneath the other. The words are divided by a horizontal line.');
|
|
702
|
+
* }
|
|
703
|
+
* </code>
|
|
704
|
+
* </div>
|
|
705
|
+
*/
|
|
706
|
+
function textWidth(text: string): number;
|
|
707
|
+
|
|
708
|
+
/**
|
|
709
|
+
* Sets the style for wrapping text when
|
|
710
|
+
* text() is called.The parameter, `style`, can be one of the following values:`WORD` starts new lines of text at spaces. If a string of text doesn't
|
|
711
|
+
* have spaces, it may overflow the text box and the canvas. This is the
|
|
712
|
+
* default style.`CHAR` starts new lines as needed to stay within the text box.`textWrap()` only works when the maximum width is set for a text box. For
|
|
713
|
+
* example, calling `text('Have a wonderful day', 0, 10, 100)` sets the
|
|
714
|
+
* maximum width to 100 pixels.Calling `textWrap()` without an argument returns the current style.
|
|
715
|
+
*
|
|
716
|
+
* @for p5
|
|
717
|
+
* @param The wrapping style to use
|
|
718
|
+
* @returns If no arguments are provided, the current wrapping style
|
|
719
|
+
* @example <div>
|
|
720
|
+
* <code>
|
|
721
|
+
* function setup() {
|
|
722
|
+
* createCanvas(100, 100);
|
|
723
|
+
*
|
|
724
|
+
* background(200);
|
|
725
|
+
*
|
|
726
|
+
* // Style the text.
|
|
727
|
+
* textSize(20);
|
|
728
|
+
* textWrap(WORD);
|
|
729
|
+
*
|
|
730
|
+
* // Display the text.
|
|
731
|
+
* text('Have a wonderful day', 0, 10, 100);
|
|
732
|
+
*
|
|
733
|
+
* describe('The text "Have a wonderful day" written across three lines.');
|
|
734
|
+
* }
|
|
735
|
+
* </code>
|
|
736
|
+
* </div>
|
|
737
|
+
* @example <div>
|
|
738
|
+
* <code>
|
|
739
|
+
* function setup() {
|
|
740
|
+
* createCanvas(100, 100);
|
|
741
|
+
*
|
|
742
|
+
* background(200);
|
|
743
|
+
*
|
|
744
|
+
* // Style the text.
|
|
745
|
+
* textSize(20);
|
|
746
|
+
* textWrap(CHAR);
|
|
747
|
+
*
|
|
748
|
+
* // Display the text.
|
|
749
|
+
* text('Have a wonderful day', 0, 10, 100);
|
|
750
|
+
*
|
|
751
|
+
* describe('The text "Have a wonderful day" written across two lines.');
|
|
752
|
+
* }
|
|
753
|
+
* </code>
|
|
754
|
+
* </div>
|
|
755
|
+
* @example <div>
|
|
756
|
+
* <code>
|
|
757
|
+
* function setup() {
|
|
758
|
+
* createCanvas(100, 100);
|
|
759
|
+
*
|
|
760
|
+
* background(200);
|
|
761
|
+
*
|
|
762
|
+
* // Style the text.
|
|
763
|
+
* textSize(20);
|
|
764
|
+
* textWrap(CHAR);
|
|
765
|
+
*
|
|
766
|
+
* // Display the text.
|
|
767
|
+
* text('祝你有美好的一天', 0, 10, 100);
|
|
768
|
+
*
|
|
769
|
+
* describe('The text "祝你有美好的一天" written across two lines.');
|
|
770
|
+
* }
|
|
771
|
+
* </code>
|
|
772
|
+
* </div>
|
|
773
|
+
*/
|
|
774
|
+
function textWrap(style: WORD | CHAR): CHAR | WORD;
|
|
775
|
+
|
|
776
|
+
/**
|
|
777
|
+
* @for p5
|
|
778
|
+
* @returns The current wrapping style
|
|
779
|
+
*/
|
|
780
|
+
function textWrap(): CHAR | WORD;
|
|
781
|
+
|
|
782
|
+
/**
|
|
783
|
+
* Computes the tight bounding box for a block of text.The `textBounds()` function calculates the precise pixel boundaries that enclose
|
|
784
|
+
* the rendered text based on the current text properties (such as font, textSize, textStyle, and
|
|
785
|
+
* alignment). If the text spans multiple lines (due to line breaks or wrapping), the function
|
|
786
|
+
* measures each line individually and then aggregates these measurements into a single bounding box.
|
|
787
|
+
* The resulting object contains the x and y coordinates along with the width (w) and height (h)
|
|
788
|
+
* of the text block.
|
|
789
|
+
*
|
|
790
|
+
* @for p5
|
|
791
|
+
* @param The text string to measure.
|
|
792
|
+
* @param The x-coordinate where the text is drawn.
|
|
793
|
+
* @param The y-coordinate where the text is drawn.
|
|
794
|
+
* @param (Optional) The maximum width available for the text block.
|
|
795
|
+
* When specified, the text may be wrapped to fit within this width.
|
|
796
|
+
* @param (Optional) The maximum height available for the text block.
|
|
797
|
+
* Any lines exceeding this height will be truncated.
|
|
798
|
+
* @returns An object with properties `x`, `y`, `w`, and `h` that represent the tight
|
|
799
|
+
* bounding box of the rendered text.
|
|
800
|
+
* @example <div>
|
|
801
|
+
* <code>
|
|
802
|
+
* function setup() {
|
|
803
|
+
* createCanvas(300, 200);
|
|
804
|
+
* background(220);
|
|
805
|
+
*
|
|
806
|
+
* // Set up text properties for clarity
|
|
807
|
+
* textSize(32);
|
|
808
|
+
* textAlign(LEFT, TOP);
|
|
809
|
+
*
|
|
810
|
+
* let txt = "Hello, World!";
|
|
811
|
+
* // Compute the bounding box for the text starting at (50, 50)
|
|
812
|
+
* let bounds = textBounds(txt, 50, 50);
|
|
813
|
+
*
|
|
814
|
+
* // Draw the text
|
|
815
|
+
* fill(0);
|
|
816
|
+
* text(txt, 50, 50);
|
|
817
|
+
*
|
|
818
|
+
* // Draw the computed bounding box in red to visualize the measured area
|
|
819
|
+
* noFill();
|
|
820
|
+
* stroke('red');
|
|
821
|
+
* rect(bounds.x, bounds.y, bounds.w, bounds.h);
|
|
822
|
+
* }
|
|
823
|
+
* </code>
|
|
824
|
+
* </div>
|
|
825
|
+
*/
|
|
826
|
+
function textBounds(str: string, x: number, y: number, width?: number, height?: number): object;
|
|
827
|
+
|
|
828
|
+
/**
|
|
829
|
+
* Sets or gets the text drawing direction.The textDirection() function allows you to specify the direction in which text is
|
|
830
|
+
* rendered on the canvas. When provided with a direction parameter (such as "ltr" for
|
|
831
|
+
* left-to-right, "rtl" for right-to-left, or "inherit"), it updates the renderer's state with that
|
|
832
|
+
* value and applies the new setting. When called without any arguments, it returns the current text
|
|
833
|
+
* direction. This function is particularly useful for rendering text in languages with different
|
|
834
|
+
* writing directions.
|
|
835
|
+
*
|
|
836
|
+
* @for p5
|
|
837
|
+
* @param The text direction to set ("ltr", "rtl", or "inherit").
|
|
838
|
+
* @returns If no arguments are provided, the current text direction, either "ltr", "rtl", or "inherit"
|
|
839
|
+
* @example <div>
|
|
840
|
+
* <code>
|
|
841
|
+
* function setup() {
|
|
842
|
+
* createCanvas(300, 300);
|
|
843
|
+
* background(240);
|
|
844
|
+
*
|
|
845
|
+
* textSize(32);
|
|
846
|
+
* textFont("Georgia");
|
|
847
|
+
* textAlign(LEFT, TOP);
|
|
848
|
+
*
|
|
849
|
+
* // Set text direction to right-to-left and draw Arabic text.
|
|
850
|
+
* textDirection("rtl");
|
|
851
|
+
* fill(0);
|
|
852
|
+
* text("مرحبًا!", 50, 50);
|
|
853
|
+
*
|
|
854
|
+
* // Set text direction to left-to-right and draw English text.
|
|
855
|
+
* textDirection("ltr");
|
|
856
|
+
* text("Hello, p5.js!", 50, 150);
|
|
857
|
+
*
|
|
858
|
+
* // Display the current text direction.
|
|
859
|
+
* textSize(16);
|
|
860
|
+
* fill(50);
|
|
861
|
+
* textAlign(LEFT, TOP);
|
|
862
|
+
* text("Current textDirection: " + textDirection(), 50, 250);
|
|
863
|
+
* }
|
|
864
|
+
* </code>
|
|
865
|
+
* </div>
|
|
866
|
+
*/
|
|
867
|
+
function textDirection(direction: string): string;
|
|
868
|
+
|
|
869
|
+
/**
|
|
870
|
+
* @for p5
|
|
871
|
+
* @returns The current text direction, either "ltr", "rtl", or "inherit"
|
|
872
|
+
*/
|
|
873
|
+
function textDirection(): string;
|
|
874
|
+
|
|
875
|
+
/**
|
|
876
|
+
* Sets or gets a single text property for the renderer.The `textProperty()` function allows you to set or retrieve a single text-related property,
|
|
877
|
+
* such as `textAlign`, `textBaseline`, `fontStyle`, or any other property
|
|
878
|
+
* that may be part of the renderer's state, its drawing context, or the canvas style.When called with a `prop` and a `value`, the function sets the property by checking
|
|
879
|
+
* for its existence in the renderer's state, the drawing context, or the canvas style. If the property is
|
|
880
|
+
* successfully modified, the function applies the updated text properties. If called with only the
|
|
881
|
+
* `prop` parameter, the function returns the current value of that property.
|
|
882
|
+
*
|
|
883
|
+
* @for p5
|
|
884
|
+
* @param The name of the text property to set or get.
|
|
885
|
+
* @param The value to set for the specified text property. If omitted, the current
|
|
886
|
+
* value of the property is returned
|
|
887
|
+
* @returns If no arguments are provided, the current value of the specified text property
|
|
888
|
+
* @example <div>
|
|
889
|
+
* <code>
|
|
890
|
+
* function setup() {
|
|
891
|
+
* createCanvas(300, 300);
|
|
892
|
+
* background(240);
|
|
893
|
+
*
|
|
894
|
+
* // Set the text alignment to CENTER and the baseline to TOP using textProperty.
|
|
895
|
+
* textProperty("textAlign", CENTER);
|
|
896
|
+
* textProperty("textBaseline", TOP);
|
|
897
|
+
*
|
|
898
|
+
* // Set additional text properties and draw the text.
|
|
899
|
+
* textSize(32);
|
|
900
|
+
* textFont("Georgia");
|
|
901
|
+
* fill(0);
|
|
902
|
+
* text("Hello, World!", width / 2, 50);
|
|
903
|
+
*
|
|
904
|
+
* // Retrieve and display the current text properties.
|
|
905
|
+
* let currentAlign = textProperty("textAlign");
|
|
906
|
+
* let currentBaseline = textProperty("textBaseline");
|
|
907
|
+
*
|
|
908
|
+
* textSize(16);
|
|
909
|
+
* textAlign(LEFT, TOP);
|
|
910
|
+
* fill(50);
|
|
911
|
+
* text("Current textAlign: " + currentAlign, 50, 150);
|
|
912
|
+
* text("Current textBaseline: " + currentBaseline, 50, 170);
|
|
913
|
+
* }
|
|
914
|
+
* </code>
|
|
915
|
+
* </div>
|
|
916
|
+
*/
|
|
917
|
+
function textProperty(prop: string, value: any): void;
|
|
918
|
+
|
|
919
|
+
/**
|
|
920
|
+
* @for p5
|
|
921
|
+
* @param The name of the text property to set or get.
|
|
922
|
+
* @returns The current value of the specified text property
|
|
923
|
+
*/
|
|
924
|
+
function textProperty(prop: string): void;
|
|
925
|
+
|
|
926
|
+
/**
|
|
927
|
+
* Gets or sets text properties in batch, similar to calling `textProperty()`
|
|
928
|
+
* multiple times.If an object is passed in, `textProperty(key, value)` will be called for you
|
|
929
|
+
* on every key/value pair in the object.If no arguments are passed in, an object will be returned with all the current
|
|
930
|
+
* properties.
|
|
931
|
+
*
|
|
932
|
+
* @for p5
|
|
933
|
+
* @param An object whose keys are properties to set, and whose
|
|
934
|
+
* values are what they should be set to.
|
|
935
|
+
*/
|
|
936
|
+
function textProperties(properties: object): void;
|
|
937
|
+
|
|
938
|
+
/**
|
|
939
|
+
* @for p5
|
|
940
|
+
* @returns An object with all the possible properties and their current values.
|
|
941
|
+
*/
|
|
942
|
+
function textProperties(): object;
|
|
943
|
+
|
|
944
|
+
/**
|
|
945
|
+
* Computes a generic (non-tight) bounding box for a block of text.The `fontBounds()` function calculates the bounding box for the text based on the
|
|
946
|
+
* font's intrinsic metrics (such as `fontBoundingBoxAscent` and
|
|
947
|
+
* `fontBoundingBoxDescent`). Unlike `textBounds()`, which measures the exact
|
|
948
|
+
* pixel boundaries of the rendered text, `fontBounds()` provides a looser measurement
|
|
949
|
+
* derived from the font’s default spacing. This measurement is useful for layout purposes where
|
|
950
|
+
* a consistent approximation of the text's dimensions is desired.
|
|
951
|
+
*
|
|
952
|
+
* @for p5
|
|
953
|
+
* @param The text string to measure.
|
|
954
|
+
* @param The x-coordinate where the text is drawn.
|
|
955
|
+
* @param The y-coordinate where the text is drawn.
|
|
956
|
+
* @param (Optional) The maximum width available for the text block.
|
|
957
|
+
* When specified, the text may be wrapped to fit within this width.
|
|
958
|
+
* @param (Optional) The maximum height available for the text block.
|
|
959
|
+
* Any lines exceeding this height will be truncated.
|
|
960
|
+
* @returns An object with properties `x`, `y`, `w`, and `h` representing the loose
|
|
961
|
+
* bounding box of the text based on the font's intrinsic metrics.
|
|
962
|
+
* @example <div>
|
|
963
|
+
* <code>
|
|
964
|
+
* function setup() {
|
|
965
|
+
* createCanvas(300, 200);
|
|
966
|
+
* background(240);
|
|
967
|
+
*
|
|
968
|
+
* textSize(32);
|
|
969
|
+
* textAlign(LEFT, TOP);
|
|
970
|
+
* textFont('Georgia');
|
|
971
|
+
*
|
|
972
|
+
* let txt = "Hello, World!";
|
|
973
|
+
* // Compute the bounding box based on the font's intrinsic metrics
|
|
974
|
+
* let bounds = fontBounds(txt, 50, 50);
|
|
975
|
+
*
|
|
976
|
+
* fill(0);
|
|
977
|
+
* text(txt, 50, 50);
|
|
978
|
+
*
|
|
979
|
+
* noFill();
|
|
980
|
+
* stroke('green');
|
|
981
|
+
* rect(bounds.x, bounds.y, bounds.w, bounds.h);
|
|
982
|
+
*
|
|
983
|
+
* noStroke();
|
|
984
|
+
* fill(50);
|
|
985
|
+
* textSize(15);
|
|
986
|
+
* text("Font Bounds: x=" + bounds.x.toFixed(1) + ", y=" + bounds.y.toFixed(1) +
|
|
987
|
+
* ", w=" + bounds.w.toFixed(1) + ", h=" + bounds.h.toFixed(1), 8, 100);
|
|
988
|
+
* }
|
|
989
|
+
* </code>
|
|
990
|
+
* </div>
|
|
991
|
+
*/
|
|
992
|
+
function fontBounds(str: string, x: number, y: number, width?: number, height?: number): object;
|
|
993
|
+
|
|
994
|
+
/**
|
|
995
|
+
* Returns the loose width of a text string based on the current font.The `fontWidth()` function measures the width of the provided text string using
|
|
996
|
+
* the font's default measurement (i.e., the width property from the text metrics returned by
|
|
997
|
+
* the browser). Unlike `textWidth()`, which calculates the tight pixel boundaries
|
|
998
|
+
* of the text glyphs, `fontWidth()` uses the font's intrinsic spacing, which may include
|
|
999
|
+
* additional space for character spacing and kerning. This makes it useful for scenarios where
|
|
1000
|
+
* an approximate width is sufficient for layout and positioning.
|
|
1001
|
+
*
|
|
1002
|
+
* @for p5
|
|
1003
|
+
* @param The text string to measure.
|
|
1004
|
+
* @returns The loose width of the text in pixels.
|
|
1005
|
+
* @example <div>
|
|
1006
|
+
* <code>
|
|
1007
|
+
* function setup() {
|
|
1008
|
+
* createCanvas(300, 200);
|
|
1009
|
+
* background(240);
|
|
1010
|
+
*
|
|
1011
|
+
* textSize(32);
|
|
1012
|
+
* textAlign(LEFT, TOP);
|
|
1013
|
+
* textFont('Georgia');
|
|
1014
|
+
*
|
|
1015
|
+
* let s = "Hello, World!";
|
|
1016
|
+
* let fw = fontWidth(s);
|
|
1017
|
+
*
|
|
1018
|
+
* fill(0);
|
|
1019
|
+
* text(s, 50, 50);
|
|
1020
|
+
*
|
|
1021
|
+
* stroke('blue');
|
|
1022
|
+
* line(50, 90, 50 + fw, 90);
|
|
1023
|
+
*
|
|
1024
|
+
* noStroke();
|
|
1025
|
+
* fill(50);
|
|
1026
|
+
* textSize(16);
|
|
1027
|
+
* text("Font width: " + fw.toFixed(2) + " pixels", 50, 100);
|
|
1028
|
+
* }
|
|
1029
|
+
* </code>
|
|
1030
|
+
* </div>
|
|
1031
|
+
*/
|
|
1032
|
+
function fontWidth(theText: string): number;
|
|
1033
|
+
|
|
1034
|
+
/**
|
|
1035
|
+
* Returns the loose ascent of the text based on the font's intrinsic metrics.The `fontAscent()` function calculates the ascent of the text using the font's
|
|
1036
|
+
* intrinsic metrics (e.g., `fontBoundingBoxAscent`). This value represents the space
|
|
1037
|
+
* above the baseline that the font inherently occupies, and is useful for layout purposes when
|
|
1038
|
+
* an approximate vertical measurement is required.
|
|
1039
|
+
*
|
|
1040
|
+
* @for p5
|
|
1041
|
+
* @returns The loose ascent value in pixels.
|
|
1042
|
+
* @example <div>
|
|
1043
|
+
* <code>
|
|
1044
|
+
* function setup() {
|
|
1045
|
+
* createCanvas(300, 300);
|
|
1046
|
+
* background(220);
|
|
1047
|
+
*
|
|
1048
|
+
* textSize(35);
|
|
1049
|
+
* textAlign(LEFT, BASELINE);
|
|
1050
|
+
* textFont('Georgia');
|
|
1051
|
+
*
|
|
1052
|
+
* let s = "Hello, p5.js!";
|
|
1053
|
+
* let x = 50, y = 150;
|
|
1054
|
+
*
|
|
1055
|
+
* fill(0);
|
|
1056
|
+
* text(s, x, y);
|
|
1057
|
+
*
|
|
1058
|
+
* // Get the font descent of the current font
|
|
1059
|
+
* let fasc = fontAscent();
|
|
1060
|
+
*
|
|
1061
|
+
* // Draw a red line at the baseline and a blue line at the ascent position
|
|
1062
|
+
* stroke('red');
|
|
1063
|
+
* line(x, y, x + 200, y); // Baseline
|
|
1064
|
+
* stroke('blue');
|
|
1065
|
+
* line(x, y - fasc, x + 200, y - fasc); // Font ascent position
|
|
1066
|
+
*
|
|
1067
|
+
* noStroke();
|
|
1068
|
+
* fill(0);
|
|
1069
|
+
* textSize(16);
|
|
1070
|
+
* text("fontAscent: " + fasc.toFixed(2) + " pixels", x, y + fdesc + 20);
|
|
1071
|
+
* }
|
|
1072
|
+
* </code>
|
|
1073
|
+
* </div>
|
|
1074
|
+
*/
|
|
1075
|
+
function fontAscent(): number;
|
|
1076
|
+
|
|
1077
|
+
/**
|
|
1078
|
+
* Returns the loose descent of the text based on the font's intrinsic metrics.The `fontDescent()` function calculates the descent of the text using the font's
|
|
1079
|
+
* intrinsic metrics (e.g., `fontBoundingBoxDescent`). This value represents the space
|
|
1080
|
+
* below the baseline that the font inherently occupies, and is useful for layout purposes when
|
|
1081
|
+
* an approximate vertical measurement is required.
|
|
1082
|
+
*
|
|
1083
|
+
* @for p5
|
|
1084
|
+
* @returns The loose descent value in pixels.
|
|
1085
|
+
* @example <div>
|
|
1086
|
+
* <code>
|
|
1087
|
+
* function setup() {
|
|
1088
|
+
* createCanvas(300, 300);
|
|
1089
|
+
* background(220);
|
|
1090
|
+
*
|
|
1091
|
+
* textSize(48);
|
|
1092
|
+
* textAlign(LEFT, BASELINE);
|
|
1093
|
+
* textFont('Georgia');
|
|
1094
|
+
*
|
|
1095
|
+
* let s = "Hello, p5.js!";
|
|
1096
|
+
* let x = 50, y = 150;
|
|
1097
|
+
*
|
|
1098
|
+
* fill(0);
|
|
1099
|
+
* text(s, x, y);
|
|
1100
|
+
*
|
|
1101
|
+
* // Get the font descent of the current font
|
|
1102
|
+
* let fdesc = fontDescent();
|
|
1103
|
+
*
|
|
1104
|
+
* // Draw a red line at the baseline and a blue line at the descent position
|
|
1105
|
+
* stroke('red');
|
|
1106
|
+
* line(x, y, x + 200, y); // Baseline
|
|
1107
|
+
* stroke('blue');
|
|
1108
|
+
* line(x, y + fdesc, x + 200, y + fdesc); // Font descent position
|
|
1109
|
+
*
|
|
1110
|
+
* noStroke();
|
|
1111
|
+
* fill(0);
|
|
1112
|
+
* textSize(16);
|
|
1113
|
+
* text("fontDescent: " + fdesc.toFixed(2) + " pixels", x, y + fdesc + 20);
|
|
1114
|
+
* }
|
|
1115
|
+
* </code>
|
|
1116
|
+
* </div>
|
|
1117
|
+
*/
|
|
1118
|
+
function fontDescent(): number;
|
|
1119
|
+
|
|
1120
|
+
/**
|
|
1121
|
+
* Sets or gets the current font weight.The textWeight() function is used to specify the weight (thickness) of the text.
|
|
1122
|
+
* When a numeric value is provided, it sets the font weight to that value and updates the
|
|
1123
|
+
* rendering properties accordingly (including the "font-variation-settings" on the canvas style).
|
|
1124
|
+
* When called without an argument, it returns the current font weight setting.
|
|
1125
|
+
*
|
|
1126
|
+
* @for p5
|
|
1127
|
+
* @param The numeric weight value to set for the text.
|
|
1128
|
+
* @returns If no arguments are provided, the current font weight
|
|
1129
|
+
* @example <div>
|
|
1130
|
+
* <code>
|
|
1131
|
+
* function setup() {
|
|
1132
|
+
* createCanvas(300, 200);
|
|
1133
|
+
* background(240);
|
|
1134
|
+
*
|
|
1135
|
+
* // Set text alignment, size, and font
|
|
1136
|
+
* textAlign(LEFT, TOP);
|
|
1137
|
+
* textSize(20);
|
|
1138
|
+
* textFont("Georgia");
|
|
1139
|
+
*
|
|
1140
|
+
* // Draw text with a normal weight (lighter appearance)
|
|
1141
|
+
* push();
|
|
1142
|
+
* textWeight(400); // Set font weight to 400
|
|
1143
|
+
* fill(0);
|
|
1144
|
+
* text("Normal", 50, 50);
|
|
1145
|
+
* let normalWeight = textWeight(); // Should return 400
|
|
1146
|
+
* pop();
|
|
1147
|
+
*
|
|
1148
|
+
* // Draw text with a bold weight (heavier appearance)
|
|
1149
|
+
* push();
|
|
1150
|
+
* textWeight(900); // Set font weight to 900
|
|
1151
|
+
* fill(0);
|
|
1152
|
+
* text("Bold", 50, 100);
|
|
1153
|
+
* let boldWeight = textWeight(); // Should return 900
|
|
1154
|
+
* pop();
|
|
1155
|
+
*
|
|
1156
|
+
* // Display the current font weight values on the canvas
|
|
1157
|
+
* textSize(16);
|
|
1158
|
+
* fill(50);
|
|
1159
|
+
* text("Normal Weight: " + normalWeight, 150, 52);
|
|
1160
|
+
* text("Bold Weight: " + boldWeight, 150, 100);
|
|
1161
|
+
* }
|
|
1162
|
+
* </code>
|
|
1163
|
+
* </div>
|
|
1164
|
+
*
|
|
1165
|
+
* <div>
|
|
1166
|
+
* <code>
|
|
1167
|
+
* let font;
|
|
1168
|
+
*
|
|
1169
|
+
* async function setup() {
|
|
1170
|
+
* createCanvas(100, 100);
|
|
1171
|
+
* font = await loadFont(
|
|
1172
|
+
* 'https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100..900;1,100..900&display=swap'
|
|
1173
|
+
* );
|
|
1174
|
+
* }
|
|
1175
|
+
*
|
|
1176
|
+
* function draw() {
|
|
1177
|
+
* background(255);
|
|
1178
|
+
* textFont(font);
|
|
1179
|
+
* textAlign(LEFT, TOP);
|
|
1180
|
+
* textSize(35);
|
|
1181
|
+
* textWeight(sin(millis() * 0.002) * 200 + 400);
|
|
1182
|
+
* text('p5*js', 0, 10);
|
|
1183
|
+
* describe('The text p5*js pulsing its weight over time');
|
|
1184
|
+
* }
|
|
1185
|
+
* </code>
|
|
1186
|
+
* </div>
|
|
1187
|
+
*/
|
|
1188
|
+
function textWeight(weight: number): number;
|
|
1189
|
+
|
|
1190
|
+
/**
|
|
1191
|
+
* @for p5
|
|
1192
|
+
* @returns The current font weight
|
|
1193
|
+
*/
|
|
1194
|
+
function textWeight(): number;
|
|
1195
|
+
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
export default function textCore(p5: any, fn: any): void;
|