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,894 @@
|
|
|
1
|
+
// This file is auto-generated from JSDoc documentation
|
|
2
|
+
|
|
3
|
+
import p5 from 'p5';
|
|
4
|
+
|
|
5
|
+
declare module 'p5' {
|
|
6
|
+
/**
|
|
7
|
+
* Converts a `String` to a floating point (decimal) `Number`.`float()` converts strings that resemble numbers, such as `'12.34'`, into
|
|
8
|
+
* numbers.The parameter, `str`, is the string value to convert. For example, calling
|
|
9
|
+
* `float('12.34')` returns the number `12.34`. If an array of strings is
|
|
10
|
+
* passed, as in `float(['12.34', '56.78'])`, then an array of numbers will be
|
|
11
|
+
* returned.Note: If a string can't be converted to a number, as in `float('giraffe')`,
|
|
12
|
+
* then the value `NaN` (not a number) will be returned.
|
|
13
|
+
*
|
|
14
|
+
* @param string to convert.
|
|
15
|
+
* @return converted number.
|
|
16
|
+
* @example <div>
|
|
17
|
+
* <code>
|
|
18
|
+
* function setup() {
|
|
19
|
+
* createCanvas(100, 100);
|
|
20
|
+
*
|
|
21
|
+
* background(200);
|
|
22
|
+
*
|
|
23
|
+
* // Create a string variable.
|
|
24
|
+
* let original = '12.3';
|
|
25
|
+
*
|
|
26
|
+
* // Convert the string to a number.
|
|
27
|
+
* let converted = float(original);
|
|
28
|
+
*
|
|
29
|
+
* // Double the converted value.
|
|
30
|
+
* let twice = converted * 2;
|
|
31
|
+
*
|
|
32
|
+
* // Style the text.
|
|
33
|
+
* textAlign(CENTER, CENTER);
|
|
34
|
+
* textSize(12);
|
|
35
|
+
*
|
|
36
|
+
* // Display the original and converted values.
|
|
37
|
+
* text(`${original} × 2 = ${twice}`, 50, 50);
|
|
38
|
+
*
|
|
39
|
+
* describe('The text "12.3 × 2 = 24.6" written in black on a gray background.');
|
|
40
|
+
* }
|
|
41
|
+
* </code>
|
|
42
|
+
* </div>
|
|
43
|
+
*
|
|
44
|
+
* <div>
|
|
45
|
+
* <code>
|
|
46
|
+
* function setup() {
|
|
47
|
+
* createCanvas(100, 100);
|
|
48
|
+
*
|
|
49
|
+
* background(200);
|
|
50
|
+
*
|
|
51
|
+
* // Create an array of strings.
|
|
52
|
+
* let original = ['60', '30', '15'];
|
|
53
|
+
*
|
|
54
|
+
* // Convert the strings to numbers.
|
|
55
|
+
* let diameters = float(original);
|
|
56
|
+
*
|
|
57
|
+
* for (let d of diameters) {
|
|
58
|
+
* // Draw a circle.
|
|
59
|
+
* circle(50, 50, d);
|
|
60
|
+
* }
|
|
61
|
+
*
|
|
62
|
+
* describe('Three white, concentric circles on a gray background.');
|
|
63
|
+
* }
|
|
64
|
+
* </code>
|
|
65
|
+
* </div>
|
|
66
|
+
*/
|
|
67
|
+
function float(str: string): number;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @param array of strings to convert.
|
|
71
|
+
* @return converted numbers.
|
|
72
|
+
*/
|
|
73
|
+
function float(ns: string[]): number[];
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Converts a `Boolean`, `String`, or decimal `Number` to an integer.`int()` converts values to integers. Integers are positive or negative
|
|
77
|
+
* numbers without decimals. If the original value has decimals, as in -34.56,
|
|
78
|
+
* they're removed to produce an integer such as -34.The parameter, `n`, is the value to convert. If `n` is a Boolean, as in
|
|
79
|
+
* `int(false)` or `int(true)`, then the number 0 (`false`) or 1 (`true`) will
|
|
80
|
+
* be returned. If `n` is a string or number, as in `int('45')` or
|
|
81
|
+
* `int(67.89)`, then an integer will be returned. If an array is passed, as
|
|
82
|
+
* in `int([12.34, 56.78])`, then an array of integers will be returned.Note: If a value can't be converted to a number, as in `int('giraffe')`,
|
|
83
|
+
* then the value `NaN` (not a number) will be returned.
|
|
84
|
+
*
|
|
85
|
+
* @param value to convert.
|
|
86
|
+
* @return converted number.
|
|
87
|
+
* @example <div>
|
|
88
|
+
* <code>
|
|
89
|
+
* function setup() {
|
|
90
|
+
* createCanvas(100, 100);
|
|
91
|
+
*
|
|
92
|
+
* background(200);
|
|
93
|
+
*
|
|
94
|
+
* // Create a Boolean variable.
|
|
95
|
+
* let original = false;
|
|
96
|
+
*
|
|
97
|
+
* // Convert the Boolean to an integer.
|
|
98
|
+
* let converted = int(original);
|
|
99
|
+
*
|
|
100
|
+
* // Style the text.
|
|
101
|
+
* textAlign(CENTER, CENTER);
|
|
102
|
+
* textSize(16);
|
|
103
|
+
*
|
|
104
|
+
* // Display the original and converted values.
|
|
105
|
+
* text(`${original} : ${converted}`, 50, 50);
|
|
106
|
+
*
|
|
107
|
+
* describe('The text "false : 0" written in black on a gray background.');
|
|
108
|
+
* }
|
|
109
|
+
* </code>
|
|
110
|
+
* </div>
|
|
111
|
+
*
|
|
112
|
+
* <div>
|
|
113
|
+
* <code>
|
|
114
|
+
* function setup() {
|
|
115
|
+
* createCanvas(100, 100);
|
|
116
|
+
*
|
|
117
|
+
* background(200);
|
|
118
|
+
*
|
|
119
|
+
* // Create a string variable.
|
|
120
|
+
* let original = '12.34';
|
|
121
|
+
*
|
|
122
|
+
* // Convert the string to an integer.
|
|
123
|
+
* let converted = int(original);
|
|
124
|
+
*
|
|
125
|
+
* // Style the text.
|
|
126
|
+
* textAlign(CENTER, CENTER);
|
|
127
|
+
* textSize(14);
|
|
128
|
+
*
|
|
129
|
+
* // Display the original and converted values.
|
|
130
|
+
* text(`${original} ≈ ${converted}`, 50, 50);
|
|
131
|
+
*
|
|
132
|
+
* describe('The text "12.34 ≈ 12" written in black on a gray background.');
|
|
133
|
+
* }
|
|
134
|
+
* </code>
|
|
135
|
+
* </div>
|
|
136
|
+
*
|
|
137
|
+
* <div>
|
|
138
|
+
* <code>
|
|
139
|
+
* function setup() {
|
|
140
|
+
* createCanvas(100, 100);
|
|
141
|
+
*
|
|
142
|
+
* background(200);
|
|
143
|
+
*
|
|
144
|
+
* // Create a decimal number variable.
|
|
145
|
+
* let original = 12.34;
|
|
146
|
+
*
|
|
147
|
+
* // Convert the decimal number to an integer.
|
|
148
|
+
* let converted = int(original);
|
|
149
|
+
*
|
|
150
|
+
* // Style the text.
|
|
151
|
+
* textAlign(CENTER, CENTER);
|
|
152
|
+
* textSize(14);
|
|
153
|
+
*
|
|
154
|
+
* // Display the original and converted values.
|
|
155
|
+
* text(`${original} ≈ ${converted}`, 50, 50);
|
|
156
|
+
*
|
|
157
|
+
* describe('The text "12.34 ≈ 12" written in black on a gray background.');
|
|
158
|
+
* }
|
|
159
|
+
* </code>
|
|
160
|
+
* </div>
|
|
161
|
+
*
|
|
162
|
+
* <div>
|
|
163
|
+
* <code>
|
|
164
|
+
* function setup() {
|
|
165
|
+
* createCanvas(100, 100);
|
|
166
|
+
*
|
|
167
|
+
* background(200);
|
|
168
|
+
*
|
|
169
|
+
* // Create an array of strings.
|
|
170
|
+
* let original = ['60', '30', '15'];
|
|
171
|
+
*
|
|
172
|
+
* // Convert the strings to integers.
|
|
173
|
+
* let diameters = int(original);
|
|
174
|
+
*
|
|
175
|
+
* for (let d of diameters) {
|
|
176
|
+
* // Draw a circle.
|
|
177
|
+
* circle(50, 50, d);
|
|
178
|
+
* }
|
|
179
|
+
*
|
|
180
|
+
* describe('Three white, concentric circles on a gray background.');
|
|
181
|
+
* }
|
|
182
|
+
* </code>
|
|
183
|
+
* </div>
|
|
184
|
+
*/
|
|
185
|
+
function int(n: string | boolean | number): number;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* @param values to convert.
|
|
189
|
+
* @return converted numbers.
|
|
190
|
+
*/
|
|
191
|
+
function int(ns: Array): number[];
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Converts a `Boolean` or `Number` to `String`.`str()` converts values to strings. See the
|
|
195
|
+
* String reference page for guidance on using
|
|
196
|
+
* template literals instead.The parameter, `n`, is the value to convert. If `n` is a Boolean, as in
|
|
197
|
+
* `str(false)` or `str(true)`, then the value will be returned as a string,
|
|
198
|
+
* as in `'false'` or `'true'`. If `n` is a number, as in `str(123)`, then its
|
|
199
|
+
* value will be returned as a string, as in `'123'`. If an array is passed,
|
|
200
|
+
* as in `str([12.34, 56.78])`, then an array of strings will be returned.
|
|
201
|
+
*
|
|
202
|
+
* @param value to convert.
|
|
203
|
+
* @return converted string.
|
|
204
|
+
* @example <div>
|
|
205
|
+
* <code>
|
|
206
|
+
* function setup() {
|
|
207
|
+
* createCanvas(100, 100);
|
|
208
|
+
*
|
|
209
|
+
* background(200);
|
|
210
|
+
*
|
|
211
|
+
* // Create a Boolean variable.
|
|
212
|
+
* let original = false;
|
|
213
|
+
*
|
|
214
|
+
* // Convert the Boolean to a string.
|
|
215
|
+
* let converted = str(original);
|
|
216
|
+
*
|
|
217
|
+
* // Style the text.
|
|
218
|
+
* textAlign(CENTER, CENTER);
|
|
219
|
+
* textSize(16);
|
|
220
|
+
*
|
|
221
|
+
* // Display the original and converted values.
|
|
222
|
+
* text(`${original} : ${converted}`, 50, 50);
|
|
223
|
+
*
|
|
224
|
+
* describe('The text "false : false" written in black on a gray background.');
|
|
225
|
+
* }
|
|
226
|
+
* </code>
|
|
227
|
+
* </div>
|
|
228
|
+
*
|
|
229
|
+
* <div>
|
|
230
|
+
* <code>
|
|
231
|
+
* function setup() {
|
|
232
|
+
* createCanvas(100, 100);
|
|
233
|
+
*
|
|
234
|
+
* background(200);
|
|
235
|
+
*
|
|
236
|
+
* // Create a number variable.
|
|
237
|
+
* let original = 123;
|
|
238
|
+
*
|
|
239
|
+
* // Convert the number to a string.
|
|
240
|
+
* let converted = str(original);
|
|
241
|
+
*
|
|
242
|
+
* // Style the text.
|
|
243
|
+
* textAlign(CENTER, CENTER);
|
|
244
|
+
* textSize(16);
|
|
245
|
+
*
|
|
246
|
+
* // Display the original and converted values.
|
|
247
|
+
* text(`${original} = ${converted}`, 50, 50);
|
|
248
|
+
*
|
|
249
|
+
* describe('The text "123 = 123" written in black on a gray background.');
|
|
250
|
+
* }
|
|
251
|
+
* </code>
|
|
252
|
+
* </div>
|
|
253
|
+
*
|
|
254
|
+
* <div>
|
|
255
|
+
* <code>
|
|
256
|
+
* function setup() {
|
|
257
|
+
* createCanvas(100, 100);
|
|
258
|
+
*
|
|
259
|
+
* background(200);
|
|
260
|
+
*
|
|
261
|
+
* // Create an array of numbers.
|
|
262
|
+
* let original = [12, 34, 56];
|
|
263
|
+
*
|
|
264
|
+
* // Convert the numbers to strings.
|
|
265
|
+
* let strings = str(original);
|
|
266
|
+
*
|
|
267
|
+
* // Create an empty string variable.
|
|
268
|
+
* let final = '';
|
|
269
|
+
*
|
|
270
|
+
* // Concatenate all the strings.
|
|
271
|
+
* for (let s of strings) {
|
|
272
|
+
* final += s;
|
|
273
|
+
* }
|
|
274
|
+
*
|
|
275
|
+
* // Style the text.
|
|
276
|
+
* textAlign(CENTER, CENTER);
|
|
277
|
+
* textSize(16);
|
|
278
|
+
*
|
|
279
|
+
* // Display the concatenated string.
|
|
280
|
+
* text(final, 50, 50);
|
|
281
|
+
*
|
|
282
|
+
* describe('The text "123456" written in black on a gray background.');
|
|
283
|
+
* }
|
|
284
|
+
* </code>
|
|
285
|
+
* </div>
|
|
286
|
+
*/
|
|
287
|
+
function str(n: string | boolean | number): string;
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Converts a `String` or `Number` to a `Boolean`.`boolean()` converts values to `true` or `false`.The parameter, `n`, is the value to convert. If `n` is a string, then
|
|
291
|
+
* `boolean('true')` will return `true` and every other string value will
|
|
292
|
+
* return `false`. If `n` is a number, then `boolean(0)` will return `false`
|
|
293
|
+
* and every other numeric value will return `true`. If an array is passed, as
|
|
294
|
+
* `in boolean([0, 1, 'true', 'blue'])`, then an array of Boolean values will
|
|
295
|
+
* be returned.
|
|
296
|
+
*
|
|
297
|
+
* @param value to convert.
|
|
298
|
+
* @return converted Boolean value.
|
|
299
|
+
* @example <div>
|
|
300
|
+
* <code>
|
|
301
|
+
* function setup() {
|
|
302
|
+
* createCanvas(100, 100);
|
|
303
|
+
*
|
|
304
|
+
* background(200);
|
|
305
|
+
*
|
|
306
|
+
* // Create a number variable.
|
|
307
|
+
* let original = 0;
|
|
308
|
+
*
|
|
309
|
+
* // Convert the number to a Boolean value.
|
|
310
|
+
* let converted = boolean(original);
|
|
311
|
+
*
|
|
312
|
+
* // Style the circle based on the converted value.
|
|
313
|
+
* if (converted === true) {
|
|
314
|
+
* fill('blue');
|
|
315
|
+
* } else {
|
|
316
|
+
* fill('red');
|
|
317
|
+
* }
|
|
318
|
+
*
|
|
319
|
+
* // Draw the circle.
|
|
320
|
+
* circle(50, 50, 40);
|
|
321
|
+
*
|
|
322
|
+
* describe('A red circle on a gray background.');
|
|
323
|
+
* }
|
|
324
|
+
* </code>
|
|
325
|
+
* </div>
|
|
326
|
+
*
|
|
327
|
+
* <div>
|
|
328
|
+
* <code>
|
|
329
|
+
* function setup() {
|
|
330
|
+
* createCanvas(100, 100);
|
|
331
|
+
*
|
|
332
|
+
* background(200);
|
|
333
|
+
*
|
|
334
|
+
* // Create a string variable.
|
|
335
|
+
* let original = 'true';
|
|
336
|
+
*
|
|
337
|
+
* // Convert the string to a Boolean value.
|
|
338
|
+
* let converted = boolean(original);
|
|
339
|
+
*
|
|
340
|
+
* // Style the circle based on the converted value.
|
|
341
|
+
* if (converted === true) {
|
|
342
|
+
* fill('blue');
|
|
343
|
+
* } else {
|
|
344
|
+
* fill('red');
|
|
345
|
+
* }
|
|
346
|
+
*
|
|
347
|
+
* // Draw the circle.
|
|
348
|
+
* circle(50, 50, 40);
|
|
349
|
+
*
|
|
350
|
+
* describe('A blue circle on a gray background.');
|
|
351
|
+
* }
|
|
352
|
+
* </code>
|
|
353
|
+
* </div>
|
|
354
|
+
*
|
|
355
|
+
* <div>
|
|
356
|
+
* <code>
|
|
357
|
+
* function setup() {
|
|
358
|
+
* createCanvas(100, 100);
|
|
359
|
+
*
|
|
360
|
+
* background(200);
|
|
361
|
+
*
|
|
362
|
+
* // Create an array of values.
|
|
363
|
+
* let original = [0, 'hi', 123, 'true'];
|
|
364
|
+
*
|
|
365
|
+
* // Convert the array to a Boolean values.
|
|
366
|
+
* let converted = boolean(original);
|
|
367
|
+
*
|
|
368
|
+
* // Iterate over the array of converted Boolean values.
|
|
369
|
+
* for (let i = 0; i < converted.length; i += 1) {
|
|
370
|
+
*
|
|
371
|
+
* // Style the circle based on the converted value.
|
|
372
|
+
* if (converted[i] === true) {
|
|
373
|
+
* fill('blue');
|
|
374
|
+
* } else {
|
|
375
|
+
* fill('red');
|
|
376
|
+
* }
|
|
377
|
+
*
|
|
378
|
+
* // Calculate the x-coordinate.
|
|
379
|
+
* let x = (i + 1) * 20;
|
|
380
|
+
*
|
|
381
|
+
* // Draw the circle.
|
|
382
|
+
* circle(x, 50, 15);
|
|
383
|
+
* }
|
|
384
|
+
*
|
|
385
|
+
* describe(
|
|
386
|
+
* 'A row of circles on a gray background. The two circles on the left are red and the two on the right are blue.'
|
|
387
|
+
* );
|
|
388
|
+
* }
|
|
389
|
+
* </code>
|
|
390
|
+
* </div>
|
|
391
|
+
*/
|
|
392
|
+
function boolean(n: string | boolean | number): boolean;
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* @param values to convert.
|
|
396
|
+
* @return converted Boolean values.
|
|
397
|
+
*/
|
|
398
|
+
function boolean(ns: Array): boolean[];
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Converts a `Boolean`, `String`, or `Number` to its byte value.`byte()` converts a value to an integer (whole number) between -128 and
|
|
402
|
+
* 127. Values greater than 127 wrap around while negative values are
|
|
403
|
+
* unchanged. For example, 128 becomes -128 and -129 remains the same.The parameter, `n`, is the value to convert. If `n` is a Boolean, as in
|
|
404
|
+
* `byte(false)` or `byte(true)`, the number 0 (`false`) or 1 (`true`) will be
|
|
405
|
+
* returned. If `n` is a string or number, as in `byte('256')` or `byte(256)`,
|
|
406
|
+
* then the byte value will be returned. Decimal values are ignored. If an
|
|
407
|
+
* array is passed, as in `byte([true, 123, '456'])`, then an array of byte
|
|
408
|
+
* values will be returned.Note: If a value can't be converted to a number, as in `byte('giraffe')`,
|
|
409
|
+
* then the value `NaN` (not a number) will be returned.
|
|
410
|
+
*
|
|
411
|
+
* @param value to convert.
|
|
412
|
+
* @return converted byte value.
|
|
413
|
+
* @example <div>
|
|
414
|
+
* <code>
|
|
415
|
+
* function setup() {
|
|
416
|
+
* createCanvas(100, 100);
|
|
417
|
+
*
|
|
418
|
+
* background(200);
|
|
419
|
+
*
|
|
420
|
+
* // Create a Boolean variable.
|
|
421
|
+
* let original = true;
|
|
422
|
+
*
|
|
423
|
+
* // Convert the Boolean to its byte value.
|
|
424
|
+
* let converted = byte(original);
|
|
425
|
+
*
|
|
426
|
+
* // Style the text.
|
|
427
|
+
* textAlign(CENTER, CENTER);
|
|
428
|
+
* textSize(16);
|
|
429
|
+
*
|
|
430
|
+
* // Display the original and converted values.
|
|
431
|
+
* text(`${original} : ${converted}`, 50, 50);
|
|
432
|
+
*
|
|
433
|
+
* describe('The text "true : 1" written in black on a gray background.');
|
|
434
|
+
* }
|
|
435
|
+
* </code>
|
|
436
|
+
* </div>
|
|
437
|
+
*
|
|
438
|
+
* <div>
|
|
439
|
+
* <code>
|
|
440
|
+
* function setup() {
|
|
441
|
+
* createCanvas(100, 100);
|
|
442
|
+
*
|
|
443
|
+
* background(200);
|
|
444
|
+
*
|
|
445
|
+
* // Create a string variable.
|
|
446
|
+
* let original = '256';
|
|
447
|
+
*
|
|
448
|
+
* // Convert the string to its byte value.
|
|
449
|
+
* let converted = byte(original);
|
|
450
|
+
*
|
|
451
|
+
* // Style the text.
|
|
452
|
+
* textAlign(CENTER, CENTER);
|
|
453
|
+
* textSize(16);
|
|
454
|
+
*
|
|
455
|
+
* // Display the original and converted values.
|
|
456
|
+
* text(`${original} : ${converted}`, 50, 50);
|
|
457
|
+
*
|
|
458
|
+
* describe('The text "256 : 0" written in black on a gray background.');
|
|
459
|
+
* }
|
|
460
|
+
* </code>
|
|
461
|
+
* </div>
|
|
462
|
+
*
|
|
463
|
+
* <div>
|
|
464
|
+
* <code>
|
|
465
|
+
* function setup() {
|
|
466
|
+
* createCanvas(100, 100);
|
|
467
|
+
*
|
|
468
|
+
* background(200);
|
|
469
|
+
*
|
|
470
|
+
* // Create a number variable.
|
|
471
|
+
* let original = 256;
|
|
472
|
+
*
|
|
473
|
+
* // Convert the number to its byte value.
|
|
474
|
+
* let converted = byte(original);
|
|
475
|
+
*
|
|
476
|
+
* // Style the text.
|
|
477
|
+
* textAlign(CENTER, CENTER);
|
|
478
|
+
* textSize(16);
|
|
479
|
+
*
|
|
480
|
+
* // Display the original and converted values.
|
|
481
|
+
* text(`${original} : ${converted}`, 50, 50);
|
|
482
|
+
*
|
|
483
|
+
* describe('The text "256 : 0" written in black on a gray background.');
|
|
484
|
+
* }
|
|
485
|
+
* </code>
|
|
486
|
+
* </div>
|
|
487
|
+
*
|
|
488
|
+
* <div>
|
|
489
|
+
* <code>
|
|
490
|
+
* function setup() {
|
|
491
|
+
* createCanvas(100, 100);
|
|
492
|
+
*
|
|
493
|
+
* background(200);
|
|
494
|
+
*
|
|
495
|
+
* // Create an array of values.
|
|
496
|
+
* let original = [false, '64', 383];
|
|
497
|
+
*
|
|
498
|
+
* // Convert the array elements to their byte values.
|
|
499
|
+
* let converted = byte(original);
|
|
500
|
+
*
|
|
501
|
+
* // Iterate over the converted array elements.
|
|
502
|
+
* for (let i = 0; i < converted.length; i += 1) {
|
|
503
|
+
*
|
|
504
|
+
* // Style the circle.
|
|
505
|
+
* fill(converted[i]);
|
|
506
|
+
*
|
|
507
|
+
* // Calculate the x-coordinate.
|
|
508
|
+
* let x = (i + 1) * 25;
|
|
509
|
+
*
|
|
510
|
+
* // Draw the circle.
|
|
511
|
+
* circle(x, 50, 20);
|
|
512
|
+
* }
|
|
513
|
+
*
|
|
514
|
+
* describe(
|
|
515
|
+
* 'Three gray circles on a gray background. The circles get lighter from left to right.'
|
|
516
|
+
* );
|
|
517
|
+
* }
|
|
518
|
+
* </code>
|
|
519
|
+
* </div>
|
|
520
|
+
*/
|
|
521
|
+
function byte(n: string | boolean | number): number;
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* @param values to convert.
|
|
525
|
+
* @return converted byte values.
|
|
526
|
+
*/
|
|
527
|
+
function byte(ns: Array): number[];
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* Converts a `Number` or `String` to a single-character `String`.`char()` converts numbers to their single-character string representations.The parameter, `n`, is the value to convert. If a number is passed, as in
|
|
531
|
+
* `char(65)`, the corresponding single-character string is returned. If a
|
|
532
|
+
* string is passed, as in `char('65')`, the string is converted to an integer
|
|
533
|
+
* (whole number) and the corresponding single-character string is returned.
|
|
534
|
+
* If an array is passed, as in `char([65, 66, 67])`, an array of
|
|
535
|
+
* single-character strings is returned.See MDN
|
|
536
|
+
* for more information about conversions.
|
|
537
|
+
*
|
|
538
|
+
* @param value to convert.
|
|
539
|
+
* @return converted single-character string.
|
|
540
|
+
* @example <div>
|
|
541
|
+
* <code>
|
|
542
|
+
* function setup() {
|
|
543
|
+
* createCanvas(100, 100);
|
|
544
|
+
*
|
|
545
|
+
* background(200);
|
|
546
|
+
*
|
|
547
|
+
* // Create a number variable.
|
|
548
|
+
* let original = 65;
|
|
549
|
+
*
|
|
550
|
+
* // Convert the number to a char.
|
|
551
|
+
* let converted = char(original);
|
|
552
|
+
*
|
|
553
|
+
* // Style the text.
|
|
554
|
+
* textAlign(CENTER, CENTER);
|
|
555
|
+
* textSize(16);
|
|
556
|
+
*
|
|
557
|
+
* // Display the original and converted values.
|
|
558
|
+
* text(`${original} : ${converted}`, 50, 50);
|
|
559
|
+
*
|
|
560
|
+
* describe('The text "65 : A" written in black on a gray background.');
|
|
561
|
+
* }
|
|
562
|
+
* </code>
|
|
563
|
+
* </div>
|
|
564
|
+
*
|
|
565
|
+
* <div>
|
|
566
|
+
* <code>
|
|
567
|
+
* function setup() {
|
|
568
|
+
* createCanvas(100, 100);
|
|
569
|
+
*
|
|
570
|
+
* background(200);
|
|
571
|
+
*
|
|
572
|
+
* // Create a string variable.
|
|
573
|
+
* let original = '65';
|
|
574
|
+
*
|
|
575
|
+
* // Convert the string to a char.
|
|
576
|
+
* let converted = char(original);
|
|
577
|
+
*
|
|
578
|
+
* // Style the text.
|
|
579
|
+
* textAlign(CENTER, CENTER);
|
|
580
|
+
* textSize(16);
|
|
581
|
+
*
|
|
582
|
+
* // Display the original and converted values.
|
|
583
|
+
* text(`${original} : ${converted}`, 50, 50);
|
|
584
|
+
*
|
|
585
|
+
* describe('The text "65 : A" written in black on a gray background.');
|
|
586
|
+
* }
|
|
587
|
+
* </code>
|
|
588
|
+
* </div>
|
|
589
|
+
*
|
|
590
|
+
* <div>
|
|
591
|
+
* <code>
|
|
592
|
+
* function setup() {
|
|
593
|
+
* createCanvas(100, 100);
|
|
594
|
+
*
|
|
595
|
+
* background(200);
|
|
596
|
+
*
|
|
597
|
+
* // Create an array of numbers.
|
|
598
|
+
* let original = ['65', 66, '67'];
|
|
599
|
+
*
|
|
600
|
+
* // Convert the string to a char.
|
|
601
|
+
* let converted = char(original);
|
|
602
|
+
*
|
|
603
|
+
* // Style the text.
|
|
604
|
+
* textAlign(CENTER, CENTER);
|
|
605
|
+
* textSize(16);
|
|
606
|
+
*
|
|
607
|
+
* // Iterate over elements of the converted array.
|
|
608
|
+
* for (let i = 0; i < converted.length; i += 1) {
|
|
609
|
+
*
|
|
610
|
+
* // Calculate the y-coordinate.
|
|
611
|
+
* let y = (i + 1) * 25;
|
|
612
|
+
*
|
|
613
|
+
* // Display the original and converted values.
|
|
614
|
+
* text(`${original[i]} : ${converted[i]}`, 50, y);
|
|
615
|
+
* }
|
|
616
|
+
*
|
|
617
|
+
* describe(
|
|
618
|
+
* 'The text "65 : A", "66 : B", and "67 : C" written on three separate lines. The text is in black on a gray background.'
|
|
619
|
+
* );
|
|
620
|
+
* }
|
|
621
|
+
* </code>
|
|
622
|
+
* </div>
|
|
623
|
+
*/
|
|
624
|
+
function char(n: string | number): string;
|
|
625
|
+
|
|
626
|
+
/**
|
|
627
|
+
* @param values to convert.
|
|
628
|
+
* @return converted single-character strings.
|
|
629
|
+
*/
|
|
630
|
+
function char(ns: Array): string[];
|
|
631
|
+
|
|
632
|
+
/**
|
|
633
|
+
* Converts a single-character `String` to a `Number`.`unchar()` converts single-character strings to their corresponding
|
|
634
|
+
* integer (whole number).The parameter, `n`, is the character to convert. For example,
|
|
635
|
+
* `unchar('A')`, returns the number 65. If an array is passed, as in
|
|
636
|
+
* `unchar(['A', 'B', 'C'])`, an array of integers is returned.
|
|
637
|
+
*
|
|
638
|
+
* @param value to convert.
|
|
639
|
+
* @return converted number.
|
|
640
|
+
* @example <div>
|
|
641
|
+
* <code>
|
|
642
|
+
* function setup() {
|
|
643
|
+
* createCanvas(100, 100);
|
|
644
|
+
*
|
|
645
|
+
* background(200);
|
|
646
|
+
*
|
|
647
|
+
* // Create a string variable.
|
|
648
|
+
* let original = 'A';
|
|
649
|
+
*
|
|
650
|
+
* // Convert the string to a number.
|
|
651
|
+
* let converted = unchar(original);
|
|
652
|
+
*
|
|
653
|
+
* // Style the text.
|
|
654
|
+
* textAlign(CENTER, CENTER);
|
|
655
|
+
* textSize(16);
|
|
656
|
+
*
|
|
657
|
+
* // Display the original and converted values.
|
|
658
|
+
* text(`${original} : ${converted}`, 50, 50);
|
|
659
|
+
*
|
|
660
|
+
* describe('The text "A : 65" written in black on a gray background.');
|
|
661
|
+
* }
|
|
662
|
+
* </code>
|
|
663
|
+
* </div>
|
|
664
|
+
*
|
|
665
|
+
* <div>
|
|
666
|
+
* <code>
|
|
667
|
+
* function setup() {
|
|
668
|
+
* createCanvas(100, 100);
|
|
669
|
+
*
|
|
670
|
+
* background(200);
|
|
671
|
+
*
|
|
672
|
+
* // Create an array of characters.
|
|
673
|
+
* let original = ['A', 'B', 'C'];
|
|
674
|
+
*
|
|
675
|
+
* // Convert the string to a number.
|
|
676
|
+
* let converted = unchar(original);
|
|
677
|
+
*
|
|
678
|
+
* // Style the text.
|
|
679
|
+
* textAlign(CENTER, CENTER);
|
|
680
|
+
* textSize(16);
|
|
681
|
+
*
|
|
682
|
+
* // Iterate over elements of the converted array.
|
|
683
|
+
* for (let i = 0; i < converted.length; i += 1) {
|
|
684
|
+
*
|
|
685
|
+
* // Calculate the y-coordinate.
|
|
686
|
+
* let y = (i + 1) * 25;
|
|
687
|
+
*
|
|
688
|
+
* // Display the original and converted values.
|
|
689
|
+
* text(`${original[i]} : ${converted[i]}`, 50, y);
|
|
690
|
+
* }
|
|
691
|
+
*
|
|
692
|
+
* describe(
|
|
693
|
+
* 'The text "A : 65", "B : 66", and "C :67" written on three separate lines. The text is in black on a gray background.'
|
|
694
|
+
* );
|
|
695
|
+
* }
|
|
696
|
+
* </code>
|
|
697
|
+
* </div>
|
|
698
|
+
*/
|
|
699
|
+
function unchar(n: string): number;
|
|
700
|
+
|
|
701
|
+
/**
|
|
702
|
+
* @param values to convert.
|
|
703
|
+
* @return converted numbers.
|
|
704
|
+
*/
|
|
705
|
+
function unchar(ns: string[]): number[];
|
|
706
|
+
|
|
707
|
+
/**
|
|
708
|
+
* Converts a `Number` to a `String` with its hexadecimal value.`hex()` converts a number to a string with its hexadecimal number value.
|
|
709
|
+
* Hexadecimal (hex) numbers are base-16, which means there are 16 unique
|
|
710
|
+
* digits. Hex extends the numbers 0–9 with the letters A–F. For example, the
|
|
711
|
+
* number `11` (eleven) in base-10 is written as the letter `B` in hex.The first parameter, `n`, is the number to convert. For example, `hex(20)`,
|
|
712
|
+
* returns the string `'00000014'`. If an array is passed, as in
|
|
713
|
+
* `hex([1, 10, 100])`, an array of hexadecimal strings is returned.The second parameter, `digits`, is optional. If a number is passed, as in
|
|
714
|
+
* `hex(20, 2)`, it sets the number of hexadecimal digits to display. For
|
|
715
|
+
* example, calling `hex(20, 2)` returns the string `'14'`.
|
|
716
|
+
*
|
|
717
|
+
* @param value to convert.
|
|
718
|
+
* @param number of digits to include.
|
|
719
|
+
* @return converted hexadecimal value.
|
|
720
|
+
* @example <div>
|
|
721
|
+
* <code>
|
|
722
|
+
* function setup() {
|
|
723
|
+
* createCanvas(100, 100);
|
|
724
|
+
*
|
|
725
|
+
* background(200);
|
|
726
|
+
*
|
|
727
|
+
* // Create a number variable.
|
|
728
|
+
* let original = 20;
|
|
729
|
+
*
|
|
730
|
+
* // Convert the number to a hex string.
|
|
731
|
+
* let converted = hex(original);
|
|
732
|
+
*
|
|
733
|
+
* // Style the text.
|
|
734
|
+
* textAlign(CENTER, CENTER);
|
|
735
|
+
* textSize(14);
|
|
736
|
+
*
|
|
737
|
+
* // Display the original and converted values.
|
|
738
|
+
* text(`${original} = ${converted}`, 50, 50);
|
|
739
|
+
*
|
|
740
|
+
* describe('The text "20 = 00000014" written in black on a gray background.');
|
|
741
|
+
* }
|
|
742
|
+
* </code>
|
|
743
|
+
* </div>
|
|
744
|
+
*
|
|
745
|
+
* <div>
|
|
746
|
+
* <code>
|
|
747
|
+
* function setup() {
|
|
748
|
+
* createCanvas(100, 100);
|
|
749
|
+
*
|
|
750
|
+
* background(200);
|
|
751
|
+
*
|
|
752
|
+
* // Create a number variable.
|
|
753
|
+
* let original = 20;
|
|
754
|
+
*
|
|
755
|
+
* // Convert the number to a hex string.
|
|
756
|
+
* // Only display two hex digits.
|
|
757
|
+
* let converted = hex(original, 2);
|
|
758
|
+
*
|
|
759
|
+
* // Style the text.
|
|
760
|
+
* textAlign(CENTER, CENTER);
|
|
761
|
+
* textSize(16);
|
|
762
|
+
*
|
|
763
|
+
* // Display the original and converted values.
|
|
764
|
+
* text(`${original} = ${converted}`, 50, 50);
|
|
765
|
+
*
|
|
766
|
+
* describe('The text "20 = 14" written in black on a gray background.');
|
|
767
|
+
* }
|
|
768
|
+
* </code>
|
|
769
|
+
* </div>
|
|
770
|
+
*
|
|
771
|
+
* <div>
|
|
772
|
+
* <code>
|
|
773
|
+
* function setup() {
|
|
774
|
+
* createCanvas(100, 100);
|
|
775
|
+
*
|
|
776
|
+
* background(200);
|
|
777
|
+
*
|
|
778
|
+
* // Create an array of numbers.
|
|
779
|
+
* let original = [1, 10, 100];
|
|
780
|
+
*
|
|
781
|
+
* // Convert the numbers to hex strings.
|
|
782
|
+
* // Only use two hex digits.
|
|
783
|
+
* let converted = hex(original, 2);
|
|
784
|
+
*
|
|
785
|
+
* // Style the text.
|
|
786
|
+
* textAlign(RIGHT, CENTER);
|
|
787
|
+
* textSize(16);
|
|
788
|
+
*
|
|
789
|
+
* // Iterate over the converted values.
|
|
790
|
+
* for (let i = 0; i < converted.length; i += 1) {
|
|
791
|
+
*
|
|
792
|
+
* // Calculate the y-coordinate.
|
|
793
|
+
* let y = (i + 1) * 25;
|
|
794
|
+
*
|
|
795
|
+
* // Display the original and converted values.
|
|
796
|
+
* text(`${ original[i]} = ${converted[i]}`, 75, y);
|
|
797
|
+
* }
|
|
798
|
+
*
|
|
799
|
+
* describe(
|
|
800
|
+
* 'The text "1 = 01", "10 = 0A", and "100 = 64" written on three separate lines. The text is in black on a gray background.'
|
|
801
|
+
* );
|
|
802
|
+
* }
|
|
803
|
+
* </code>
|
|
804
|
+
* </div>
|
|
805
|
+
*/
|
|
806
|
+
function hex(n: number, digits?: number): string;
|
|
807
|
+
|
|
808
|
+
/**
|
|
809
|
+
* @param values to convert.
|
|
810
|
+
* @return converted hexadecimal values.
|
|
811
|
+
*/
|
|
812
|
+
function hex(ns: number[], digits?: number): string[];
|
|
813
|
+
|
|
814
|
+
/**
|
|
815
|
+
* Converts a `String` with a hexadecimal value to a `Number`.`unhex()` converts a string with its hexadecimal number value to a number.
|
|
816
|
+
* Hexadecimal (hex) numbers are base-16, which means there are 16 unique
|
|
817
|
+
* digits. Hex extends the numbers 0–9 with the letters A–F. For example, the
|
|
818
|
+
* number `11` (eleven) in base-10 is written as the letter `B` in hex.The first parameter, `n`, is the hex string to convert. For example,
|
|
819
|
+
* `unhex('FF')`, returns the number 255. If an array is passed, as in
|
|
820
|
+
* `unhex(['00', '80', 'FF'])`, an array of numbers is returned.
|
|
821
|
+
*
|
|
822
|
+
* @param value to convert.
|
|
823
|
+
* @return converted number.
|
|
824
|
+
* @example <div>
|
|
825
|
+
* <code>
|
|
826
|
+
* function setup() {
|
|
827
|
+
* createCanvas(100, 100);
|
|
828
|
+
*
|
|
829
|
+
* background(200);
|
|
830
|
+
*
|
|
831
|
+
* // Create a a hex string variable
|
|
832
|
+
* let original = 'FF';
|
|
833
|
+
*
|
|
834
|
+
* // Convert the hex string to a number.
|
|
835
|
+
* let converted = unhex(original);
|
|
836
|
+
*
|
|
837
|
+
* // Style the text.
|
|
838
|
+
* textAlign(CENTER, CENTER);
|
|
839
|
+
* textSize(16);
|
|
840
|
+
*
|
|
841
|
+
* // Display the original and converted values.
|
|
842
|
+
* text(`${original} = ${converted}`, 50, 50);
|
|
843
|
+
*
|
|
844
|
+
* describe('The text "FF = 255" written in black on a gray background.');
|
|
845
|
+
* }
|
|
846
|
+
* </code>
|
|
847
|
+
* </div>
|
|
848
|
+
*
|
|
849
|
+
* <div>
|
|
850
|
+
* <code>
|
|
851
|
+
* function setup() {
|
|
852
|
+
* createCanvas(100, 100);
|
|
853
|
+
*
|
|
854
|
+
* background(200);
|
|
855
|
+
*
|
|
856
|
+
* // Create an array of numbers.
|
|
857
|
+
* let original = ['00', '80', 'FF'];
|
|
858
|
+
*
|
|
859
|
+
* // Convert the numbers to hex strings.
|
|
860
|
+
* // Only use two hex digits.
|
|
861
|
+
* let converted = unhex(original, 2);
|
|
862
|
+
*
|
|
863
|
+
* // Style the text.
|
|
864
|
+
* textAlign(RIGHT, CENTER);
|
|
865
|
+
* textSize(16);
|
|
866
|
+
*
|
|
867
|
+
* // Iterate over the converted values.
|
|
868
|
+
* for (let i = 0; i < converted.length; i += 1) {
|
|
869
|
+
*
|
|
870
|
+
* // Calculate the y-coordinate.
|
|
871
|
+
* let y = (i + 1) * 25;
|
|
872
|
+
*
|
|
873
|
+
* // Display the original and converted values.
|
|
874
|
+
* text(`${ original[i]} = ${converted[i]}`, 80, y);
|
|
875
|
+
* }
|
|
876
|
+
*
|
|
877
|
+
* describe(
|
|
878
|
+
* 'The text "00 = 0", "80 = 128", and "FF = 255" written on three separate lines. The text is in black on a gray background.'
|
|
879
|
+
* );
|
|
880
|
+
* }
|
|
881
|
+
* </code>
|
|
882
|
+
* </div>
|
|
883
|
+
*/
|
|
884
|
+
function unhex(n: string): number;
|
|
885
|
+
|
|
886
|
+
/**
|
|
887
|
+
* @param values to convert.
|
|
888
|
+
* @return converted numbers.
|
|
889
|
+
*/
|
|
890
|
+
function unhex(ns: string[]): number[];
|
|
891
|
+
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
export default function conversion(p5: any, fn: any): void;
|