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.
Files changed (267) hide show
  1. package/{src → dist}/accessibility/color_namer.js +48 -3
  2. package/{src → dist}/accessibility/describe.js +12 -2
  3. package/{src → dist}/accessibility/gridOutput.js +2 -2
  4. package/dist/accessibility/index.js +60 -0
  5. package/{src → dist}/accessibility/outputs.js +23 -2
  6. package/{src → dist}/accessibility/textOutput.js +2 -2
  7. package/dist/app.js +120 -0
  8. package/{src → dist}/color/color_conversion.js +48 -10
  9. package/{src → dist}/color/color_spaces/hsb.js +3 -1
  10. package/dist/color/creating_reading.js +3 -0
  11. package/dist/color/index.js +13 -0
  12. package/dist/color/p5.Color.culori.js +1 -0
  13. package/dist/color/p5.Color.js +3 -0
  14. package/{src → dist}/color/setting.js +9 -6
  15. package/{src/core/constants.js → dist/constants-tYr0tCl8.js} +284 -132
  16. package/{src → dist}/core/States.js +3 -1
  17. package/dist/core/constants.js +1 -0
  18. package/{src → dist}/core/environment.js +12 -10
  19. package/{src → dist}/core/friendly_errors/browser_errors.js +1 -1
  20. package/{src → dist}/core/friendly_errors/fes_core.js +14 -44
  21. package/{src → dist}/core/friendly_errors/file_errors.js +6 -3
  22. package/dist/core/friendly_errors/index.js +23 -0
  23. package/dist/core/friendly_errors/param_validator.js +5421 -0
  24. package/{src → dist}/core/friendly_errors/sketch_reader.js +50 -4
  25. package/{src → dist}/core/friendly_errors/sketch_verifier.js +6 -6
  26. package/{src → dist}/core/friendly_errors/stacktrace.js +3 -5
  27. package/{src → dist}/core/friendly_errors/validate_params.js +50 -41
  28. package/{src → dist}/core/helpers.js +9 -6
  29. package/dist/core/init.js +105 -0
  30. package/dist/core/internationalization.js +302 -0
  31. package/dist/core/legacy.js +73 -0
  32. package/dist/core/main.js +44 -0
  33. package/dist/core/noop.js +3 -0
  34. package/dist/core/p5.Graphics.js +40 -0
  35. package/dist/core/p5.Renderer.js +11 -0
  36. package/dist/core/p5.Renderer2D.js +44 -0
  37. package/dist/core/reference.js +1 -0
  38. package/dist/core/rendering.js +40 -0
  39. package/{src → dist}/core/structure.js +3 -3
  40. package/{src → dist}/core/transform.js +2 -2
  41. package/{src/color/creating_reading.js → dist/creating_reading-Cr8L2Jnm.js} +841 -13
  42. package/{src → dist}/data/index.js +3 -1
  43. package/{src → dist}/data/local_storage.js +2 -8
  44. package/{src → dist}/dom/dom.js +19 -13
  45. package/dist/dom/index.js +18 -0
  46. package/{src → dist}/dom/p5.Element.js +14 -12
  47. package/{src → dist}/dom/p5.File.js +4 -4
  48. package/{src → dist}/dom/p5.MediaElement.js +10 -4
  49. package/{src → dist}/events/acceleration.js +26 -26
  50. package/{src → dist}/events/index.js +3 -1
  51. package/{src → dist}/events/keyboard.js +14 -12
  52. package/{src → dist}/events/pointer.js +16 -17
  53. package/dist/image/const.js +9 -0
  54. package/{src → dist}/image/filterRenderer2D.js +57 -37
  55. package/{src → dist}/image/filters.js +1 -3
  56. package/dist/image/image.js +40 -0
  57. package/dist/image/index.js +51 -0
  58. package/dist/image/loading_displaying.js +40 -0
  59. package/dist/image/p5.Image.js +11 -0
  60. package/{src → dist}/image/pixels.js +5 -3
  61. package/{src → dist}/io/csv.js +72 -70
  62. package/dist/io/files.js +40 -0
  63. package/dist/io/index.js +51 -0
  64. package/{src → dist}/io/p5.Table.js +6 -6
  65. package/{src → dist}/io/p5.TableRow.js +5 -6
  66. package/{src → dist}/io/p5.XML.js +2 -5
  67. package/{src → dist}/io/utilities.js +1 -1
  68. package/{src/core/p5.Renderer2D.js → dist/main-CAxvgiOV.js} +738 -57
  69. package/{src → dist}/math/Matrices/Matrix.js +10 -8
  70. package/{src → dist}/math/Matrices/MatrixInterface.js +5 -3
  71. package/{src → dist}/math/Matrices/MatrixNumjs.js +12 -26
  72. package/{src → dist}/math/calculation.js +2 -2
  73. package/{src → dist}/math/index.js +6 -3
  74. package/{src → dist}/math/math.js +3 -3
  75. package/{src → dist}/math/noise.js +2 -2
  76. package/{src → dist}/math/p5.Matrix.js +7 -4
  77. package/{src → dist}/math/p5.Vector.js +6 -6
  78. package/{src → dist}/math/random.js +2 -2
  79. package/{src → dist}/math/trigonometry.js +16 -15
  80. package/{src/image/p5.Image.js → dist/p5.Renderer-Swjl9HQO.js} +393 -22
  81. package/dist/rendering-B5TRR7aY.js +24960 -0
  82. package/{src → dist}/shape/2d_primitives.js +18 -17
  83. package/{src → dist}/shape/attributes.js +18 -17
  84. package/{src → dist}/shape/curves.js +2 -2
  85. package/{src → dist}/shape/custom_shapes.js +44 -64
  86. package/{src → dist}/shape/index.js +10 -2
  87. package/{src → dist}/shape/vertex.js +2 -3
  88. package/dist/type/index.js +25 -0
  89. package/{src → dist}/type/lib/Typr.js +76 -94
  90. package/{src → dist}/type/p5.Font.js +37 -63
  91. package/{src → dist}/type/textCore.js +35 -58
  92. package/{src → dist}/type/unicodeRanges.js +3 -1
  93. package/{src → dist}/utilities/conversion.js +2 -2
  94. package/{src → dist}/utilities/index.js +3 -1
  95. package/{src → dist}/utilities/time_date.js +6 -7
  96. package/{src → dist}/utilities/utility_functions.js +2 -2
  97. package/dist/webgl/3d_primitives.js +40 -0
  98. package/{src → dist}/webgl/GeometryBufferCache.js +3 -1
  99. package/{src → dist}/webgl/GeometryBuilder.js +12 -8
  100. package/{src → dist}/webgl/ShaderGenerator.js +79 -82
  101. package/{src → dist}/webgl/ShapeBuilder.js +26 -23
  102. package/dist/webgl/index.js +76 -0
  103. package/{src → dist}/webgl/interaction.js +7 -6
  104. package/dist/webgl/light.js +40 -0
  105. package/{src → dist}/webgl/loading.js +45 -12
  106. package/dist/webgl/material.js +40 -0
  107. package/dist/webgl/p5.Camera.js +40 -0
  108. package/{src → dist}/webgl/p5.DataArray.js +3 -5
  109. package/dist/webgl/p5.Framebuffer.js +40 -0
  110. package/{src → dist}/webgl/p5.Geometry.js +12 -15
  111. package/{src → dist}/webgl/p5.Quat.js +5 -4
  112. package/{src → dist}/webgl/p5.RenderBuffer.js +2 -3
  113. package/dist/webgl/p5.RendererGL.js +40 -0
  114. package/dist/webgl/p5.Shader.js +40 -0
  115. package/dist/webgl/p5.Texture.js +40 -0
  116. package/{src → dist}/webgl/text.js +78 -38
  117. package/lib/p5.esm.js +296 -194
  118. package/lib/p5.js +296 -194
  119. package/lib/p5.min.js +1 -1
  120. package/package.json +17 -17
  121. package/translations/dev.js +6 -6
  122. package/translations/index.js +1 -1
  123. package/types/accessibility/color_namer.d.ts +8 -0
  124. package/types/accessibility/describe.d.ts +184 -0
  125. package/types/accessibility/gridOutput.d.ts +8 -0
  126. package/types/accessibility/outputs.d.ts +235 -0
  127. package/types/accessibility/textOutput.d.ts +8 -0
  128. package/types/color/color_conversion.d.ts +47 -0
  129. package/types/color/creating_reading.d.ts +1348 -0
  130. package/types/color/p5.Color.d.ts +1070 -0
  131. package/types/color/setting.d.ts +2085 -0
  132. package/types/core/constants.d.ts +341 -0
  133. package/types/core/environment.d.ts +668 -0
  134. package/types/core/friendly_errors/fes_core.d.ts +8 -0
  135. package/types/core/friendly_errors/file_errors.d.ts +8 -0
  136. package/types/core/friendly_errors/param_validator.d.ts +30 -0
  137. package/types/core/friendly_errors/sketch_reader.d.ts +8 -0
  138. package/types/core/friendly_errors/stacktrace.d.ts +11 -0
  139. package/types/core/friendly_errors/validate_params.d.ts +8 -0
  140. package/types/core/helpers.d.ts +8 -0
  141. package/types/core/legacy.d.ts +8 -0
  142. package/types/core/main.d.ts +5996 -0
  143. package/types/core/p5.Graphics.d.ts +484 -0
  144. package/types/core/p5.Renderer.d.ts +14 -0
  145. package/types/core/reference.d.ts +8 -0
  146. package/types/core/rendering.d.ts +481 -0
  147. package/types/core/structure.d.ts +492 -0
  148. package/types/core/transform.d.ts +1638 -0
  149. package/types/data/local_storage.d.ts +323 -0
  150. package/types/dom/dom.d.ts +1295 -0
  151. package/types/dom/p5.Element.d.ts +2011 -0
  152. package/types/dom/p5.File.d.ts +13 -0
  153. package/types/dom/p5.MediaElement.d.ts +1249 -0
  154. package/types/events/acceleration.d.ts +193 -0
  155. package/types/events/keyboard.d.ts +499 -0
  156. package/types/events/pointer.d.ts +782 -0
  157. package/types/global.d.ts +5542 -0
  158. package/types/image/filterRenderer2D.d.ts +54 -0
  159. package/types/image/image.d.ts +326 -0
  160. package/types/image/loading_displaying.d.ts +580 -0
  161. package/types/image/p5.Image.d.ts +5882 -0
  162. package/types/image/pixels.d.ts +832 -0
  163. package/types/io/files.d.ts +1447 -0
  164. package/types/io/p5.Table.d.ts +1247 -0
  165. package/types/io/p5.TableRow.d.ts +343 -0
  166. package/types/io/p5.XML.d.ts +1188 -0
  167. package/types/math/Matrices/Matrix.d.ts +1029 -0
  168. package/types/math/Matrices/MatrixNumjs.d.ts +8 -0
  169. package/types/math/calculation.d.ts +923 -0
  170. package/types/math/math.d.ts +90 -0
  171. package/types/math/noise.d.ts +311 -0
  172. package/types/math/p5.Matrix.d.ts +8 -0
  173. package/types/math/p5.Vector.d.ts +3416 -0
  174. package/types/math/random.d.ts +267 -0
  175. package/types/math/trigonometry.d.ts +663 -0
  176. package/types/p5.d.ts +6663 -0
  177. package/types/shape/2d_primitives.d.ts +1033 -0
  178. package/types/shape/attributes.d.ts +466 -0
  179. package/types/shape/curves.d.ts +740 -0
  180. package/types/shape/custom_shapes.d.ts +888 -0
  181. package/types/shape/vertex.d.ts +1141 -0
  182. package/types/type/p5.Font.d.ts +575 -0
  183. package/types/type/textCore.d.ts +1198 -0
  184. package/types/utilities/conversion.d.ts +894 -0
  185. package/types/utilities/time_date.d.ts +295 -0
  186. package/types/utilities/utility_functions.d.ts +587 -0
  187. package/types/webgl/3d_primitives.d.ts +1432 -0
  188. package/types/webgl/ShaderGenerator.d.ts +8 -0
  189. package/types/webgl/interaction.d.ts +371 -0
  190. package/types/webgl/light.d.ts +1184 -0
  191. package/types/webgl/loading.d.ts +481 -0
  192. package/types/webgl/material.d.ts +2656 -0
  193. package/types/webgl/p5.Camera.d.ts +3023 -0
  194. package/types/webgl/p5.DataArray.d.ts +61 -0
  195. package/types/webgl/p5.Framebuffer.d.ts +760 -0
  196. package/types/webgl/p5.Geometry.d.ts +1191 -0
  197. package/types/webgl/p5.Quat.d.ts +45 -0
  198. package/types/webgl/p5.RendererGL.d.ts +234 -0
  199. package/types/webgl/p5.Shader.d.ts +660 -0
  200. package/types/webgl/p5.Texture.d.ts +61 -0
  201. package/types/webgl/text.d.ts +74 -0
  202. package/src/README.md +0 -27
  203. package/src/accessibility/index.js +0 -13
  204. package/src/app.js +0 -61
  205. package/src/color/index.js +0 -9
  206. package/src/color/p5.Color.culori.js +0 -66
  207. package/src/color/p5.Color.js +0 -851
  208. package/src/core/README.md +0 -91
  209. package/src/core/friendly_errors/index.js +0 -13
  210. package/src/core/friendly_errors/param_validator.js +0 -561
  211. package/src/core/init.js +0 -58
  212. package/src/core/internationalization.js +0 -195
  213. package/src/core/legacy.js +0 -29
  214. package/src/core/main.js +0 -689
  215. package/src/core/noop.js +0 -1
  216. package/src/core/p5.Graphics.js +0 -696
  217. package/src/core/p5.Renderer.js +0 -408
  218. package/src/core/reference.js +0 -2060
  219. package/src/core/rendering.js +0 -697
  220. package/src/dom/index.js +0 -11
  221. package/src/image/const.js +0 -6
  222. package/src/image/image.js +0 -731
  223. package/src/image/index.js +0 -15
  224. package/src/image/loading_displaying.js +0 -1431
  225. package/src/io/files.js +0 -2210
  226. package/src/io/index.js +0 -11
  227. package/src/math/README.md +0 -40
  228. package/src/type/index.js +0 -9
  229. package/src/webgl/3d_primitives.js +0 -2741
  230. package/src/webgl/index.js +0 -37
  231. package/src/webgl/light.js +0 -1851
  232. package/src/webgl/material.js +0 -3854
  233. package/src/webgl/p5.Camera.js +0 -4010
  234. package/src/webgl/p5.Framebuffer.js +0 -1865
  235. package/src/webgl/p5.RendererGL.js +0 -2867
  236. package/src/webgl/p5.Shader.js +0 -1505
  237. package/src/webgl/p5.Texture.js +0 -541
  238. package/src/webgl/shaders/basic.frag +0 -6
  239. package/src/webgl/shaders/filters/base.frag +0 -22
  240. package/src/webgl/shaders/filters/base.vert +0 -19
  241. package/src/webgl/shaders/filters/blur.frag +0 -60
  242. package/src/webgl/shaders/filters/default.vert +0 -18
  243. package/src/webgl/shaders/filters/dilate.frag +0 -39
  244. package/src/webgl/shaders/filters/erode.frag +0 -39
  245. package/src/webgl/shaders/filters/gray.frag +0 -16
  246. package/src/webgl/shaders/filters/invert.frag +0 -15
  247. package/src/webgl/shaders/filters/opaque.frag +0 -12
  248. package/src/webgl/shaders/filters/posterize.frag +0 -29
  249. package/src/webgl/shaders/filters/threshold.frag +0 -23
  250. package/src/webgl/shaders/font.frag +0 -216
  251. package/src/webgl/shaders/font.vert +0 -44
  252. package/src/webgl/shaders/imageLight.vert +0 -33
  253. package/src/webgl/shaders/imageLightDiffused.frag +0 -82
  254. package/src/webgl/shaders/imageLightSpecular.frag +0 -134
  255. package/src/webgl/shaders/light.vert +0 -37
  256. package/src/webgl/shaders/light_texture.frag +0 -26
  257. package/src/webgl/shaders/lighting.glsl +0 -227
  258. package/src/webgl/shaders/line.frag +0 -74
  259. package/src/webgl/shaders/line.vert +0 -294
  260. package/src/webgl/shaders/normal.frag +0 -6
  261. package/src/webgl/shaders/normal.vert +0 -72
  262. package/src/webgl/shaders/phong.frag +0 -84
  263. package/src/webgl/shaders/phong.vert +0 -87
  264. package/src/webgl/shaders/point.frag +0 -29
  265. package/src/webgl/shaders/point.vert +0 -19
  266. package/src/webgl/shaders/sphereMapping.frag +0 -26
  267. package/src/webgl/shaders/webgl2Compatibility.glsl +0 -34
@@ -0,0 +1,193 @@
1
+ // This file is auto-generated from JSDoc documentation
2
+
3
+ import p5 from 'p5';
4
+
5
+ declare module 'p5' {
6
+ /**
7
+ * The setMoveThreshold() function is used to set the movement threshold for
8
+ * the deviceMoved() function. The default threshold is set to 0.5.
9
+ *
10
+ * @param The threshold value
11
+ * @example <div class="norender">
12
+ * <code>
13
+ * // Run this example on a mobile device
14
+ * // You will need to move the device incrementally further
15
+ * // the closer the square's color gets to white in order to change the value.
16
+ *
17
+ * let value = 0;
18
+ * let threshold = 0.5;
19
+ * function setup() {
20
+ * setMoveThreshold(threshold);
21
+ * }
22
+ * function draw() {
23
+ * fill(value);
24
+ * rect(25, 25, 50, 50);
25
+ * describe(`50-by-50 black rect in center of canvas.
26
+ * turns white on mobile when device moves`);
27
+ * }
28
+ * function deviceMoved() {
29
+ * value = value + 5;
30
+ * threshold = threshold + 0.1;
31
+ * if (value > 255) {
32
+ * value = 0;
33
+ * threshold = 30;
34
+ * }
35
+ * setMoveThreshold(threshold);
36
+ * }
37
+ * </code>
38
+ * </div>
39
+ */
40
+ function setMoveThreshold(value: number): void;
41
+
42
+ /**
43
+ * The setShakeThreshold() function is used to set the movement threshold for
44
+ * the deviceShaken() function. The default threshold is set to 30.
45
+ *
46
+ * @param The threshold value
47
+ * @example <div class="norender">
48
+ * <code>
49
+ * // Run this example on a mobile device
50
+ * // You will need to shake the device more firmly
51
+ * // the closer the box's fill gets to white in order to change the value.
52
+ *
53
+ * let value = 0;
54
+ * let threshold = 30;
55
+ * function setup() {
56
+ * setShakeThreshold(threshold);
57
+ * }
58
+ * function draw() {
59
+ * fill(value);
60
+ * rect(25, 25, 50, 50);
61
+ * describe(`50-by-50 black rect in center of canvas.
62
+ * turns white on mobile when device is being shaked`);
63
+ * }
64
+ * function deviceMoved() {
65
+ * value = value + 5;
66
+ * threshold = threshold + 5;
67
+ * if (value > 255) {
68
+ * value = 0;
69
+ * threshold = 30;
70
+ * }
71
+ * setShakeThreshold(threshold);
72
+ * }
73
+ * </code>
74
+ * </div>
75
+ */
76
+ function setShakeThreshold(value: number): void;
77
+
78
+ /**
79
+ * The deviceMoved() function is called when the device is moved by more than
80
+ * the threshold value along X, Y or Z axis. The default threshold is set to 0.5.
81
+ * The threshold value can be changed using setMoveThreshold().
82
+ *
83
+ * @example <div class="norender">
84
+ * <code>
85
+ * // Run this example on a mobile device
86
+ * // Move the device around
87
+ * // to change the value.
88
+ *
89
+ * let value = 0;
90
+ * function draw() {
91
+ * fill(value);
92
+ * rect(25, 25, 50, 50);
93
+ * describe(`50-by-50 black rect in center of canvas.
94
+ * turns white on mobile when device moves`);
95
+ * }
96
+ * function deviceMoved() {
97
+ * value = value + 5;
98
+ * if (value > 255) {
99
+ * value = 0;
100
+ * }
101
+ * }
102
+ * </code>
103
+ * </div>
104
+ */
105
+ function deviceMoved(): void;
106
+
107
+ /**
108
+ * The deviceTurned() function is called when the device rotates by
109
+ * more than 90 degrees continuously.The axis that triggers the deviceTurned() method is stored in the turnAxis
110
+ * variable. The deviceTurned() method can be locked to trigger on any axis:
111
+ * X, Y or Z by comparing the turnAxis variable to 'X', 'Y' or 'Z'.
112
+ *
113
+ * @example <div class="norender">
114
+ * <code>
115
+ * // Run this example on a mobile device
116
+ * // Rotate the device by 90 degrees
117
+ * // to change the value.
118
+ *
119
+ * let value = 0;
120
+ * function draw() {
121
+ * fill(value);
122
+ * rect(25, 25, 50, 50);
123
+ * describe(`50-by-50 black rect in center of canvas.
124
+ * turns white on mobile when device turns`);
125
+ * }
126
+ * function deviceTurned() {
127
+ * if (value === 0) {
128
+ * value = 255;
129
+ * } else if (value === 255) {
130
+ * value = 0;
131
+ * }
132
+ * }
133
+ * </code>
134
+ * </div>
135
+ * <div>
136
+ * <code>
137
+ * // Run this example on a mobile device
138
+ * // Rotate the device by 90 degrees in the
139
+ * // X-axis to change the value.
140
+ *
141
+ * let value = 0;
142
+ * function draw() {
143
+ * fill(value);
144
+ * rect(25, 25, 50, 50);
145
+ * describe(`50-by-50 black rect in center of canvas.
146
+ * turns white on mobile when x-axis turns`);
147
+ * }
148
+ * function deviceTurned() {
149
+ * if (turnAxis === 'X') {
150
+ * if (value === 0) {
151
+ * value = 255;
152
+ * } else if (value === 255) {
153
+ * value = 0;
154
+ * }
155
+ * }
156
+ * }
157
+ * </code>
158
+ * </div>
159
+ */
160
+ function deviceTurned(): void;
161
+
162
+ /**
163
+ * The deviceShaken() function is called when the device total acceleration
164
+ * changes of accelerationX and accelerationY values is more than
165
+ * the threshold value. The default threshold is set to 30.
166
+ * The threshold value can be changed using setShakeThreshold().
167
+ *
168
+ * @example <div class="norender">
169
+ * <code>
170
+ * // Run this example on a mobile device
171
+ * // Shake the device to change the value.
172
+ *
173
+ * let value = 0;
174
+ * function draw() {
175
+ * fill(value);
176
+ * rect(25, 25, 50, 50);
177
+ * describe(`50-by-50 black rect in center of canvas.
178
+ * turns white on mobile when device shakes`);
179
+ * }
180
+ * function deviceShaken() {
181
+ * value = value + 5;
182
+ * if (value > 255) {
183
+ * value = 0;
184
+ * }
185
+ * }
186
+ * </code>
187
+ * </div>
188
+ */
189
+ function deviceShaken(): void;
190
+
191
+ }
192
+
193
+ export default function acceleration(p5: any, fn: any): void;
@@ -0,0 +1,499 @@
1
+ // This file is auto-generated from JSDoc documentation
2
+
3
+ import p5 from 'p5';
4
+
5
+ declare module 'p5' {
6
+ /**
7
+ * The onblur function is called when the user is no longer focused
8
+ * on the p5 element. Because the keyup events will not fire if the user is
9
+ * not focused on the element we must assume all keys currently down have
10
+ * been released.
11
+ *
12
+ */
13
+ function _onblur(e: any): void;
14
+
15
+ /**
16
+ * A function that's called once when any key is pressed.Declaring the function `keyPressed()` sets a code block to run once
17
+ * automatically when the user presses any key:`function keyPressed() {
18
+ * // Code to run.
19
+ * }`The key and keyCode
20
+ * variables will be updated with the most recently typed value when
21
+ * `keyPressed()` is called by p5.js:`function keyPressed() {
22
+ * if (key === 'c') {
23
+ * // Code to run.
24
+ * }
25
+ *
26
+ * if (keyCode === 13) { // Enter key
27
+ * // Code to run.
28
+ * }
29
+ * }`The parameter, `event`, is optional. `keyPressed()` is always passed a
30
+ * KeyboardEvent
31
+ * object with properties that describe the key press event:`function keyPressed(event) {
32
+ * // Code to run that uses the event.
33
+ * console.log(event);
34
+ * }`Browsers may have default behaviors attached to various key events. For
35
+ * example, some browsers may jump to the bottom of a web page when the
36
+ * `SPACE` key is pressed. To prevent any default behavior for this event, add
37
+ * `return false;` to the end of the function.
38
+ *
39
+ * @param optional `KeyboardEvent` callback argument.
40
+ * @example <div>
41
+ * <code>
42
+ * // Click on the canvas to begin detecting key presses.
43
+ *
44
+ * let value = 0;
45
+ *
46
+ * function setup() {
47
+ * createCanvas(100, 100);
48
+ *
49
+ * describe(
50
+ * 'A gray square with a black square at its center. The inner square changes color when the user presses a key.'
51
+ * );
52
+ * }
53
+ *
54
+ * function draw() {
55
+ * background(200);
56
+ *
57
+ * // Style the square.
58
+ * fill(value);
59
+ *
60
+ * // Draw the square.
61
+ * square(25, 25, 50);
62
+ * }
63
+ *
64
+ * // Toggle the background color when the user presses a key.
65
+ * function keyPressed() {
66
+ * if (value === 0) {
67
+ * value = 255;
68
+ * } else {
69
+ * value = 0;
70
+ * }
71
+ * // Uncomment to prevent any default behavior.
72
+ * // return false;
73
+ * }
74
+ * </code>
75
+ * </div>
76
+ *
77
+ * <div>
78
+ * <code>
79
+ * // Click on the canvas to begin detecting key presses.
80
+ *
81
+ * let value = 0;
82
+ *
83
+ * function setup() {
84
+ * createCanvas(100, 100);
85
+ *
86
+ * describe(
87
+ * 'A gray square with a white square at its center. The inner square turns black when the user presses the "b" key. It turns white when the user presses the "a" key.'
88
+ * );
89
+ * }
90
+ *
91
+ * function draw() {
92
+ * background(200);
93
+ *
94
+ * // Style the square.
95
+ * fill(value);
96
+ *
97
+ * // Draw the square.
98
+ * square(25, 25, 50);
99
+ * }
100
+ *
101
+ * // Reassign value when the user presses the 'a' or 'b' key.
102
+ * function keyPressed() {
103
+ * if (key === 'a') {
104
+ * value = 255;
105
+ * } else if (key === 'b') {
106
+ * value = 0;
107
+ * }
108
+ * // Uncomment to prevent any default behavior.
109
+ * // return false;
110
+ * }
111
+ * </code>
112
+ * </div>
113
+ *
114
+ * <div>
115
+ * <code>
116
+ * // Click on the canvas to begin detecting key presses.
117
+ *
118
+ * let value = 0;
119
+ *
120
+ * function setup() {
121
+ * createCanvas(100, 100);
122
+ *
123
+ * describe(
124
+ * 'A gray square with a black square at its center. The inner square turns white when the user presses the left arrow key. It turns black when the user presses the right arrow key.'
125
+ * );
126
+ * }
127
+ *
128
+ * function draw() {
129
+ * background(200);
130
+ *
131
+ * // Style the square.
132
+ * fill(value);
133
+ *
134
+ * // Draw the square.
135
+ * square(25, 25, 50);
136
+ * }
137
+ *
138
+ * // Toggle the background color when the user presses an arrow key.
139
+ * function keyPressed() {
140
+ * if (keyCode === 37) { // Left arrow key
141
+ * value = 255;
142
+ * } else if (keyCode === 39) { // Right arrow key
143
+ * value = 0;
144
+ * }
145
+ * // Uncomment to prevent any default behavior.
146
+ * // return false;
147
+ * }
148
+ * </code>
149
+ * </div>
150
+ */
151
+ function keyPressed(event?: KeyboardEvent): void;
152
+
153
+ /**
154
+ * A function that's called once when any key is released.Declaring the function `keyReleased()` sets a code block to run once
155
+ * automatically when the user releases any key:`function keyReleased() {
156
+ * // Code to run.
157
+ * }`The key and keyCode
158
+ * variables will be updated with the most recently released value when
159
+ * `keyReleased()` is called by p5.js:`function keyReleased() {
160
+ * if (key === 'c') {
161
+ * // Code to run.
162
+ * }
163
+ *
164
+ * if (keyCode === 13) { // Enter key
165
+ * // Code to run.
166
+ * }
167
+ * }`The parameter, `event`, is optional. `keyReleased()` is always passed a
168
+ * KeyboardEvent
169
+ * object with properties that describe the key press event:`function keyReleased(event) {
170
+ * // Code to run that uses the event.
171
+ * console.log(event);
172
+ * }`Browsers may have default behaviors attached to various key events. To
173
+ * prevent any default behavior for this event, add `return false;` to the end
174
+ * of the function.
175
+ *
176
+ * @param optional `KeyboardEvent` callback argument.
177
+ * @example <div>
178
+ * <code>
179
+ * // Click on the canvas to begin detecting key presses.
180
+ *
181
+ * let value = 0;
182
+ *
183
+ * function setup() {
184
+ * createCanvas(100, 100);
185
+ *
186
+ * describe(
187
+ * 'A gray square with a black square at its center. The inner square changes color when the user releases a key.'
188
+ * );
189
+ * }
190
+ *
191
+ * function draw() {
192
+ * background(200);
193
+ *
194
+ * // Style the square.
195
+ * fill(value);
196
+ *
197
+ * // Draw the square.
198
+ * square(25, 25, 50);
199
+ * }
200
+ *
201
+ * // Toggle value when the user releases a key.
202
+ * function keyReleased() {
203
+ * if (value === 0) {
204
+ * value = 255;
205
+ * } else {
206
+ * value = 0;
207
+ * }
208
+ * // Uncomment to prevent any default behavior.
209
+ * // return false;
210
+ * }
211
+ * </code>
212
+ * </div>
213
+ *
214
+ * <div>
215
+ * <code>
216
+ * // Click on the canvas to begin detecting key presses.
217
+ *
218
+ * let value = 0;
219
+ *
220
+ * function setup() {
221
+ * createCanvas(100, 100);
222
+ *
223
+ * describe(
224
+ * 'A gray square with a black square at its center. The inner square becomes white when the user releases the "w" key.'
225
+ * );
226
+ * }
227
+ *
228
+ * function draw() {
229
+ * background(200);
230
+ *
231
+ * // Style the square.
232
+ * fill(value);
233
+ *
234
+ * // Draw the square.
235
+ * square(25, 25, 50);
236
+ * }
237
+ *
238
+ * // Set value to 255 the user releases the 'w' key.
239
+ * function keyReleased() {
240
+ * if (key === 'w') {
241
+ * value = 255;
242
+ * }
243
+ * // Uncomment to prevent any default behavior.
244
+ * // return false;
245
+ * }
246
+ * </code>
247
+ * </div>
248
+ *
249
+ * <div>
250
+ * <code>
251
+ * // Click on the canvas to begin detecting key presses.
252
+ *
253
+ * let value = 0;
254
+ *
255
+ * function setup() {
256
+ * createCanvas(100, 100);
257
+ *
258
+ * describe(
259
+ * 'A gray square with a black square at its center. The inner square turns white when the user presses and releases the left arrow key. It turns black when the user presses and releases the right arrow key.'
260
+ * );
261
+ * }
262
+ *
263
+ * function draw() {
264
+ * background(200);
265
+ *
266
+ * // Style the square.
267
+ * fill(value);
268
+ *
269
+ * // Draw the square.
270
+ * square(25, 25, 50);
271
+ * }
272
+ *
273
+ * // Toggle the background color when the user releases an arrow key.
274
+ * function keyReleased() {
275
+ * if (keyCode === 37) { // Left arrow key
276
+ * value = 255;
277
+ * } else if (keyCode === 39) { // Right arrow key
278
+ * value = 0;
279
+ * }
280
+ * // Uncomment to prevent any default behavior.
281
+ * // return false;
282
+ * }
283
+ * </code>
284
+ * </div>
285
+ */
286
+ function keyReleased(event?: KeyboardEvent): void;
287
+
288
+ /**
289
+ * A function that's called once when keys with printable characters are pressed.Declaring the function `keyTyped()` sets a code block to run once
290
+ * automatically when the user presses any key with a printable character such
291
+ * as `a` or 1. Modifier keys such as `SHIFT`, `CONTROL`, and the arrow keys
292
+ * will be ignored:`function keyTyped() {
293
+ * // Code to run.
294
+ * }`The key and keyCode
295
+ * variables will be updated with the most recently released value when
296
+ * `keyTyped()` is called by p5.js:`function keyTyped() {
297
+ * // Check for the "c" character using key.
298
+ * if (key === 'c') {
299
+ * // Code to run.
300
+ * }
301
+ *
302
+ * // Check for "c" using keyCode.
303
+ * if (keyCode === 67) { // 67 is the ASCII code for 'c'
304
+ * // Code to run.
305
+ * }
306
+ * }`The parameter, `event`, is optional. `keyTyped()` is always passed a
307
+ * KeyboardEvent
308
+ * object with properties that describe the key press event:`function keyReleased(event) {
309
+ * // Code to run that uses the event.
310
+ * console.log(event);
311
+ * }`Note: Use the keyPressed() function and
312
+ * keyCode system variable to respond to modifier
313
+ * keys such as `ALT`.Browsers may have default behaviors attached to various key events. To
314
+ * prevent any default behavior for this event, add `return false;` to the end
315
+ * of the function.
316
+ *
317
+ * @param optional `KeyboardEvent` callback argument.
318
+ * @example <div>
319
+ * <code>
320
+ * // Click on the canvas to begin detecting key presses.
321
+ * // Note: Pressing special keys such as SPACE have no effect.
322
+ *
323
+ * let value = 0;
324
+ *
325
+ * function setup() {
326
+ * createCanvas(100, 100);
327
+ *
328
+ * describe(
329
+ * 'A gray square with a white square at its center. The inner square changes color when the user presses a key.'
330
+ * );
331
+ * }
332
+ *
333
+ * function draw() {
334
+ * background(200);
335
+ *
336
+ * // Style the square.
337
+ * fill(value);
338
+ *
339
+ * // Draw the square.
340
+ * square(25, 25, 50);
341
+ * }
342
+ *
343
+ * // Toggle the square's color when the user types a printable key.
344
+ * function keyTyped() {
345
+ * if (value === 0) {
346
+ * value = 255;
347
+ * } else {
348
+ * value = 0;
349
+ * }
350
+ * // Uncomment to prevent any default behavior.
351
+ * // return false;
352
+ * }
353
+ * </code>
354
+ * </div>
355
+ *
356
+ * <div>
357
+ * <code>
358
+ * // Click on the canvas to begin detecting key presses.
359
+ *
360
+ * let value = 0;
361
+ *
362
+ * function setup() {
363
+ * createCanvas(100, 100);
364
+ *
365
+ * describe(
366
+ * 'A gray square with a white square at its center. The inner square turns black when the user types the "b" key. It turns white when the user types the "a" key.'
367
+ * );
368
+ * }
369
+ *
370
+ * function draw() {
371
+ * background(200);
372
+ *
373
+ * // Style the square.
374
+ * fill(value);
375
+ *
376
+ * // Draw the square.
377
+ * square(25, 25, 50);
378
+ * }
379
+ *
380
+ * // Reassign value when the user types the 'a' or 'b' key.
381
+ * function keyTyped() {
382
+ * if (key === 'a') {
383
+ * value = 255;
384
+ * } else if (key === 'b') {
385
+ * value = 0;
386
+ * }
387
+ * // Uncomment to prevent any default behavior.
388
+ * // return false;
389
+ * }
390
+ * </code>
391
+ * </div>
392
+ */
393
+ function keyTyped(event?: KeyboardEvent): void;
394
+
395
+ /**
396
+ * Returns `true` if the key it’s checking is pressed and `false` if not.`keyIsDown()` is helpful when checking for multiple different key presses.
397
+ * For example, `keyIsDown()` can be used to check if both `LEFT_ARROW` and
398
+ * `UP_ARROW` are pressed:`if (keyIsDown(LEFT_ARROW) && keyIsDown(UP_ARROW)) {
399
+ * // Move diagonally.
400
+ * }``keyIsDown()` can check for key presses using
401
+ * keyCode values, as in `keyIsDown(37)` or
402
+ * `keyIsDown(LEFT_ARROW)`. Key codes can be found on websites such as
403
+ * keycode.info.
404
+ *
405
+ * @param key to check.
406
+ * @return whether the key is down or not.
407
+ * @example <div>
408
+ * <code>
409
+ * // Click on the canvas to begin detecting key presses.
410
+ *
411
+ * let x = 50;
412
+ * let y = 50;
413
+ *
414
+ * function setup() {
415
+ * createCanvas(100, 100);
416
+ *
417
+ * background(200);
418
+ *
419
+ * describe(
420
+ * 'A gray square with a black circle at its center. The circle moves when the user presses an arrow key. It leaves a trail as it moves.'
421
+ * );
422
+ * }
423
+ *
424
+ * function draw() {
425
+ * // Update x and y if an arrow key is pressed.
426
+ * if (keyIsDown(LEFT_ARROW) === true) {
427
+ * x -= 1;
428
+ * }
429
+ *
430
+ * if (keyIsDown(RIGHT_ARROW) === true) {
431
+ * x += 1;
432
+ * }
433
+ *
434
+ * if (keyIsDown(UP_ARROW) === true) {
435
+ * y -= 1;
436
+ * }
437
+ *
438
+ * if (keyIsDown(DOWN_ARROW) === true) {
439
+ * y += 1;
440
+ * }
441
+ *
442
+ * // Style the circle.
443
+ * fill(0);
444
+ *
445
+ * // Draw the circle.
446
+ * circle(x, y, 5);
447
+ * }
448
+ * </code>
449
+ * </div>
450
+ *
451
+ * <div>
452
+ * <code>
453
+ * // Click on the canvas to begin detecting key presses.
454
+ *
455
+ * let x = 50;
456
+ * let y = 50;
457
+ *
458
+ * function setup() {
459
+ * createCanvas(100, 100);
460
+ *
461
+ * background(200);
462
+ *
463
+ * describe(
464
+ * 'A gray square with a black circle at its center. The circle moves when the user presses an arrow key. It leaves a trail as it moves.'
465
+ * );
466
+ * }
467
+ *
468
+ * function draw() {
469
+ * // Update x and y if an arrow key is pressed.
470
+ * if (keyIsDown('ArrowLeft') === true) {
471
+ * x -= 1;
472
+ * }
473
+ *
474
+ * if (keyIsDown('ArrowRight') === true) {
475
+ * x += 1;
476
+ * }
477
+ *
478
+ * if (keyIsDown('ArrowUp') === true) {
479
+ * y -= 1;
480
+ * }
481
+ *
482
+ * if (keyIsDown('ArrowDown') === true) {
483
+ * y += 1;
484
+ * }
485
+ *
486
+ * // Style the circle.
487
+ * fill(0);
488
+ *
489
+ * // Draw the circle.
490
+ * circle(x, y, 5);
491
+ * }
492
+ * </code>
493
+ * </div>
494
+ */
495
+ function keyIsDown(code: number | string): boolean;
496
+
497
+ }
498
+
499
+ export default function keyboard(p5: any, fn: any): void;