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,1249 @@
1
+ // This file is auto-generated from JSDoc documentation
2
+
3
+ import p5 from 'p5';
4
+
5
+ declare module 'p5' {
6
+ class MediaElement extends Element {
7
+ constructor(elt: string);
8
+
9
+ /**
10
+ * Plays audio or video from a media element.
11
+ */
12
+ play(): void;
13
+
14
+ /**
15
+ * Stops a media element and sets its current time to 0.Calling `media.play()` will restart playing audio/video from the beginning.
16
+ */
17
+ stop(): void;
18
+
19
+ /**
20
+ * Pauses a media element.Calling `media.play()` will resume playing audio/video from the moment it paused.
21
+ */
22
+ pause(): void;
23
+
24
+ /**
25
+ * Plays the audio/video repeatedly in a loop.
26
+ */
27
+ loop(): void;
28
+
29
+ /**
30
+ * Stops the audio/video from playing in a loop.The media will stop when it finishes playing.
31
+ */
32
+ noLoop(): void;
33
+
34
+ /**
35
+ * Sets the audio/video to play once it's loaded.The parameter, `shouldAutoplay`, is optional. Calling
36
+ * `media.autoplay()` without an argument causes the media to play
37
+ * automatically. If `true` is passed, as in `media.autoplay(true)`, the
38
+ * media will automatically play. If `false` is passed, as in
39
+ * `media.autoPlay(false)`, it won't play automatically.
40
+ *
41
+ * @param
42
+ * @param
43
+ */
44
+ autoplay(val: any, shouldAutoplay: boolean): void;
45
+
46
+ /**
47
+ * Sets the audio/video volume.Calling `media.volume()` without an argument returns the current volume
48
+ * as a number in the range 0 (off) to 1 (maximum).The parameter, `val`, is optional. It's a number that sets the volume
49
+ * from 0 (off) to 1 (maximum). For example, calling `media.volume(0.5)`
50
+ * sets the volume to half of its maximum.
51
+ *
52
+ * @param
53
+ */
54
+ volume(val: any): number;
55
+
56
+ volume(val: number): void;
57
+
58
+ /**
59
+ * Sets the audio/video playback speed.The parameter, `val`, is optional. It's a number that sets the playback
60
+ * speed. 1 plays the media at normal speed, 0.5 plays it at half speed, 2
61
+ * plays it at double speed, and so on. -1 plays the media at normal speed
62
+ * in reverse.Calling `media.speed()` returns the current speed as a number.Note: Not all browsers support backward playback. Even if they do,
63
+ * playback might not be smooth.
64
+ *
65
+ * @param
66
+ */
67
+ speed(val: any): number;
68
+
69
+ speed(val: any, speed: number): void;
70
+
71
+ /**
72
+ * Sets the media element's playback time.The parameter, `time`, is optional. It's a number that specifies the
73
+ * time, in seconds, to jump to when playback begins.Calling `media.time()` without an argument returns the number of seconds
74
+ * the audio/video has played.Note: Time resets to 0 when looping media restarts.
75
+ *
76
+ * @param
77
+ */
78
+ time(val: any): number;
79
+
80
+ time(val: any, time: number): void;
81
+
82
+ /**
83
+ * Returns the audio/video's duration in seconds.
84
+ */
85
+ duration(): number;
86
+
87
+ /**
88
+ * Calls a function when the audio/video reaches the end of its playback.The element is passed as an argument to the callback function.Note: The function won't be called if the media is looping.
89
+ *
90
+ * @param
91
+ */
92
+ onended(callback: Function): void;
93
+
94
+ /**
95
+ * Sends the element's audio to an output.The parameter, `audioNode`, can be an `AudioNode` or an object from the
96
+ * `p5.sound` library.If no element is provided, as in `myElement.connect()`, the element
97
+ * connects to the main output. All connections are removed by the
98
+ * `.disconnect()` method.Note: This method is meant to be used with the p5.sound.js addon library.
99
+ *
100
+ * @param
101
+ * @param
102
+ */
103
+ connect(obj: any, audioNode: AudioNode | object): void;
104
+
105
+ /**
106
+ * Disconnect all Web Audio routing, including to the main output.This is useful if you want to re-route the output through audio effects,
107
+ * for example.
108
+ */
109
+ disconnect(): void;
110
+
111
+ /**
112
+ * Show the default
113
+ * HTMLMediaElement
114
+ * controls.Note: The controls vary between web browsers.
115
+ */
116
+ showControls(): void;
117
+
118
+ /**
119
+ * Hide the default
120
+ * HTMLMediaElement
121
+ * controls.
122
+ */
123
+ hideControls(): void;
124
+
125
+ /**
126
+ * Schedules a function to call when the audio/video reaches a specific time
127
+ * during its playback.The first parameter, `time`, is the time, in seconds, when the function
128
+ * should run. This value is passed to `callback` as its first argument.The second parameter, `callback`, is the function to call at the specified
129
+ * cue time.The third parameter, `value`, is optional and can be any type of value.
130
+ * `value` is passed to `callback`.Calling `media.addCue()` returns an ID as a string. This is useful for
131
+ * removing the cue later.
132
+ *
133
+ * @param
134
+ * @param
135
+ * @param
136
+ * @param
137
+ */
138
+ addCue(time: number, callback: Function, val: any, value: object): number;
139
+
140
+ /**
141
+ * Removes a callback based on its ID.
142
+ *
143
+ * @param
144
+ */
145
+ removeCue(id: number): void;
146
+
147
+ /**
148
+ * Removes all functions scheduled with `media.addCue()`.
149
+ */
150
+ clearCues(): void;
151
+
152
+ }
153
+
154
+ /**
155
+ * Creates a `<video>` element for simple audio/video playback.`createVideo()` returns a new
156
+ * p5.MediaElement object. Videos are shown by
157
+ * default. They can be hidden by calling `video.hide()` and drawn to the
158
+ * canvas using image().The first parameter, `src`, is the path the video. If a single string is
159
+ * passed, as in `'assets/topsecret.mp4'`, a single video is loaded. An array
160
+ * of strings can be used to load the same video in different formats. For
161
+ * example, `['assets/topsecret.mp4', 'assets/topsecret.ogv', 'assets/topsecret.webm']`.
162
+ * This is useful for ensuring that the video can play across different browsers with
163
+ * different capabilities. See
164
+ * MDN
165
+ * for more information about supported formats.The second parameter, `callback`, is optional. It's a function to call once
166
+ * the video is ready to play.
167
+ *
168
+ * @param path to a video file, or an array of paths for
169
+ * supporting different browsers.
170
+ * @param function to call once the video is ready to play.
171
+ * @return new <a href="#/p5.MediaElement">p5.MediaElement</a> object.
172
+ * @example <div class='notest'>
173
+ * <code>
174
+ * function setup() {
175
+ * noCanvas();
176
+ *
177
+ * // Load a video and add it to the page.
178
+ * // Note: this may not work in some browsers.
179
+ * let video = createVideo('assets/small.mp4');
180
+ *
181
+ * // Show the default video controls.
182
+ * video.showControls();
183
+ *
184
+ * describe('A video of a toy robot with playback controls beneath it.');
185
+ * }
186
+ * </code>
187
+ * </div>
188
+ *
189
+ * <div class='notest'>
190
+ * <code>
191
+ * function setup() {
192
+ * noCanvas();
193
+ *
194
+ * // Load a video and add it to the page.
195
+ * // Provide an array options for different file formats.
196
+ * let video = createVideo(
197
+ * ['assets/small.mp4', 'assets/small.ogv', 'assets/small.webm']
198
+ * );
199
+ *
200
+ * // Show the default video controls.
201
+ * video.showControls();
202
+ *
203
+ * describe('A video of a toy robot with playback controls beneath it.');
204
+ * }
205
+ * </code>
206
+ * </div>
207
+ *
208
+ * <div class='notest'>
209
+ * <code>
210
+ * let video;
211
+ *
212
+ * function setup() {
213
+ * noCanvas();
214
+ *
215
+ * // Load a video and add it to the page.
216
+ * // Provide an array options for different file formats.
217
+ * // Call mute() once the video loads.
218
+ * video = createVideo(
219
+ * ['assets/small.mp4', 'assets/small.ogv', 'assets/small.webm'],
220
+ * muteVideo
221
+ * );
222
+ *
223
+ * // Show the default video controls.
224
+ * video.showControls();
225
+ *
226
+ * describe('A video of a toy robot with playback controls beneath it.');
227
+ * }
228
+ *
229
+ * // Mute the video once it loads.
230
+ * function muteVideo() {
231
+ * video.volume(0);
232
+ * }
233
+ * </code>
234
+ * </div>
235
+ */
236
+ function createVideo(src: string | string[], callback?: Function): p5.MediaElement;
237
+
238
+ /**
239
+ * AUDIO STUFF *
240
+ *
241
+ */
242
+ function createAudio(src: any, callback: any): void;
243
+
244
+ /**
245
+ * Creates a hidden `&lt;audio&gt;` element for simple audio playback.`createAudio()` returns a new
246
+ * p5.MediaElement object.The first parameter, `src`, is the path the video. If a single string is
247
+ * passed, as in `'assets/video.mp4'`, a single video is loaded. An array
248
+ * of strings can be used to load the same video in different formats. For
249
+ * example, `['assets/video.mp4', 'assets/video.ogv', 'assets/video.webm']`.
250
+ * This is useful for ensuring that the video can play across different
251
+ * browsers with different capabilities. See
252
+ * MDN
253
+ * for more information about supported formats.The second parameter, `callback`, is optional. It's a function to call once
254
+ * the audio is ready to play.
255
+ *
256
+ * @param path to an audio file, or an array of paths
257
+ * for supporting different browsers.
258
+ * @param function to call once the audio is ready to play.
259
+ * @return new <a href="#/p5.MediaElement">p5.MediaElement</a> object.
260
+ * @example <div class='notest'>
261
+ * <code>
262
+ * function setup() {
263
+ * noCanvas();
264
+ *
265
+ * // Load the audio.
266
+ * let beat = createAudio('assets/beat.mp3');
267
+ *
268
+ * // Show the default audio controls.
269
+ * beat.showControls();
270
+ *
271
+ * describe('An audio beat plays when the user double-clicks the square.');
272
+ * }
273
+ * </code>
274
+ * </div>
275
+ */
276
+ function createAudio(src?: string | string[], callback?: Function): p5.MediaElement;
277
+
278
+ /**
279
+ * Creates a `&lt;video&gt;` element that "captures" the audio/video stream from
280
+ * the webcam and microphone.`createCapture()` returns a new
281
+ * p5.MediaElement object. Videos are shown by
282
+ * default. They can be hidden by calling `capture.hide()` and drawn to the
283
+ * canvas using image().The first parameter, `type`, is optional. It sets the type of capture to
284
+ * use. By default, `createCapture()` captures both audio and video. If `VIDEO`
285
+ * is passed, as in `createCapture(VIDEO)`, only video will be captured.
286
+ * If `AUDIO` is passed, as in `createCapture(AUDIO)`, only audio will be
287
+ * captured. A constraints object can also be passed to customize the stream.
288
+ * See the
289
+ * W3C documentation for possible properties. Different browsers support different
290
+ * properties.The 'flipped' property is an optional property which can be set to `{flipped:true}`
291
+ * to mirror the video output.If it is true then it means that video will be mirrored
292
+ * or flipped and if nothing is mentioned then by default it will be `false`.The second parameter,`callback`, is optional. It's a function to call once
293
+ * the capture is ready for use. The callback function should have one
294
+ * parameter, `stream`, that's a
295
+ * MediaStream object.Note: `createCapture()` only works when running a sketch locally or using HTTPS. Learn more
296
+ * here
297
+ * and here.
298
+ *
299
+ * @param type of capture, either AUDIO or VIDEO,
300
+ * or a constraints object. Both video and audio
301
+ * audio streams are captured by default.
302
+ * @param flip the capturing video and mirror the output with `{flipped:true}`. By
303
+ * default it is false.
304
+ * @param function to call once the stream
305
+ * has loaded.
306
+ * @return new <a href="#/p5.MediaElement">p5.MediaElement</a> object.
307
+ * @example <div class='notest'>
308
+ * <code>
309
+ * function setup() {
310
+ * noCanvas();
311
+ *
312
+ * // Create the video capture.
313
+ * createCapture(VIDEO);
314
+ *
315
+ * describe('A video stream from the webcam.');
316
+ * }
317
+ * </code>
318
+ * </div>
319
+ *
320
+ * <div class='notest'>
321
+ * <code>
322
+ * let capture;
323
+ *
324
+ * function setup() {
325
+ * createCanvas(100, 100);
326
+ *
327
+ * // Create the video capture and hide the element.
328
+ * capture = createCapture(VIDEO);
329
+ * capture.hide();
330
+ *
331
+ * describe('A video stream from the webcam with inverted colors.');
332
+ * }
333
+ *
334
+ * function draw() {
335
+ * // Draw the video capture within the canvas.
336
+ * image(capture, 0, 0, width, width * capture.height / capture.width);
337
+ *
338
+ * // Invert the colors in the stream.
339
+ * filter(INVERT);
340
+ * }
341
+ * </code>
342
+ * </div>
343
+ * <div class='notest'>
344
+ * <code>
345
+ * let capture;
346
+ *
347
+ * function setup() {
348
+ * createCanvas(100, 100);
349
+ *
350
+ * // Create the video capture with mirrored output.
351
+ * capture = createCapture(VIDEO,{ flipped:true });
352
+ * capture.size(100,100);
353
+ *
354
+ * describe('A video stream from the webcam with flipped or mirrored output.');
355
+ * }
356
+ *
357
+ * </code>
358
+ * </div>
359
+ *
360
+ * <div class='notest norender'>
361
+ * <code>
362
+ * function setup() {
363
+ * createCanvas(480, 120);
364
+ *
365
+ * // Create a constraints object.
366
+ * let constraints = {
367
+ * video: {
368
+ * mandatory: {
369
+ * minWidth: 1280,
370
+ * minHeight: 720
371
+ * },
372
+ * optional: [{ maxFrameRate: 10 }]
373
+ * },
374
+ * audio: false
375
+ * };
376
+ *
377
+ * // Create the video capture.
378
+ * createCapture(constraints);
379
+ *
380
+ * describe('A video stream from the webcam.');
381
+ * }
382
+ * </code>
383
+ * </div>
384
+ */
385
+ function createCapture(...args: any[], type?: AUDIO | VIDEO | object, flipped?: object, callback?: Function): p5.MediaElement;
386
+
387
+ /**
388
+ * Helpers for create methods.
389
+ *
390
+ */
391
+ function addElement(elt: any, pInst: any, media: any): void;
392
+
393
+ /**
394
+ * Plays audio or video from a media element.
395
+ *
396
+ * @example <div>
397
+ * <code>
398
+ * let beat;
399
+ *
400
+ * function setup() {
401
+ * createCanvas(100, 100);
402
+ *
403
+ * background(200);
404
+ *
405
+ * // Style the text.
406
+ * textAlign(CENTER);
407
+ * textSize(16);
408
+ *
409
+ * // Display a message.
410
+ * text('Click to play', 50, 50);
411
+ *
412
+ * // Create a p5.MediaElement using createAudio().
413
+ * beat = createAudio('assets/beat.mp3');
414
+ *
415
+ * describe('The text "Click to play" written in black on a gray background. A beat plays when the user clicks the square.');
416
+ * }
417
+ *
418
+ * // Play the beat when the user presses the mouse.
419
+ * function mousePressed() {
420
+ * beat.play();
421
+ * }
422
+ * </code>
423
+ * </div>
424
+ */
425
+ function play(): void;
426
+
427
+ /**
428
+ * Stops a media element and sets its current time to 0.Calling `media.play()` will restart playing audio/video from the beginning.
429
+ *
430
+ * @example <div>
431
+ * <code>
432
+ * let beat;
433
+ * let isStopped = true;
434
+ *
435
+ * function setup() {
436
+ * createCanvas(100, 100);
437
+ *
438
+ * // Create a p5.MediaElement using createAudio().
439
+ * beat = createAudio('assets/beat.mp3');
440
+ *
441
+ * describe('The text "Click to start" written in black on a gray background. The beat starts or stops when the user presses the mouse.');
442
+ * }
443
+ *
444
+ * function draw() {
445
+ * background(200);
446
+ *
447
+ * // Style the text.
448
+ * textAlign(CENTER);
449
+ * textSize(16);
450
+ *
451
+ * // Display different instructions based on playback.
452
+ * if (isStopped === true) {
453
+ * text('Click to start', 50, 50);
454
+ * } else {
455
+ * text('Click to stop', 50, 50);
456
+ * }
457
+ * }
458
+ *
459
+ * // Adjust playback when the user presses the mouse.
460
+ * function mousePressed() {
461
+ * if (isStopped === true) {
462
+ * // If the beat is stopped, play it.
463
+ * beat.play();
464
+ * isStopped = false;
465
+ * } else {
466
+ * // If the beat is playing, stop it.
467
+ * beat.stop();
468
+ * isStopped = true;
469
+ * }
470
+ * }
471
+ * </code>
472
+ * </div>
473
+ */
474
+ function stop(): void;
475
+
476
+ /**
477
+ * Pauses a media element.Calling `media.play()` will resume playing audio/video from the moment it paused.
478
+ *
479
+ * @example <div>
480
+ * <code>
481
+ * let beat;
482
+ * let isPaused = true;
483
+ *
484
+ * function setup() {
485
+ * createCanvas(100, 100);
486
+ *
487
+ * // Create a p5.MediaElement using createAudio().
488
+ * beat = createAudio('assets/beat.mp3');
489
+ *
490
+ * describe('The text "Click to play" written in black on a gray background. The beat plays or pauses when the user clicks the square.');
491
+ * }
492
+ *
493
+ * function draw() {
494
+ * background(200);
495
+ *
496
+ * // Style the text.
497
+ * textAlign(CENTER);
498
+ * textSize(16);
499
+ *
500
+ * // Display different instructions based on playback.
501
+ * if (isPaused === true) {
502
+ * text('Click to play', 50, 50);
503
+ * } else {
504
+ * text('Click to pause', 50, 50);
505
+ * }
506
+ * }
507
+ *
508
+ * // Adjust playback when the user presses the mouse.
509
+ * function mousePressed() {
510
+ * if (isPaused === true) {
511
+ * // If the beat is paused,
512
+ * // play it.
513
+ * beat.play();
514
+ * isPaused = false;
515
+ * } else {
516
+ * // If the beat is playing,
517
+ * // pause it.
518
+ * beat.pause();
519
+ * isPaused = true;
520
+ * }
521
+ * }
522
+ * </code>
523
+ * </div>
524
+ */
525
+ function pause(): void;
526
+
527
+ /**
528
+ * Plays the audio/video repeatedly in a loop.
529
+ *
530
+ * @example <div>
531
+ * <code>
532
+ * let beat;
533
+ * let isLooping = false;
534
+ *
535
+ * function setup() {
536
+ * createCanvas(100, 100);
537
+ *
538
+ * background(200);
539
+ *
540
+ * // Create a p5.MediaElement using createAudio().
541
+ * beat = createAudio('assets/beat.mp3');
542
+ *
543
+ * describe('The text "Click to loop" written in black on a gray background. A beat plays repeatedly in a loop when the user clicks. The beat stops when the user clicks again.');
544
+ * }
545
+ *
546
+ * function draw() {
547
+ * background(200);
548
+ *
549
+ * // Style the text.
550
+ * textAlign(CENTER);
551
+ * textSize(16);
552
+ *
553
+ * // Display different instructions based on playback.
554
+ * if (isLooping === true) {
555
+ * text('Click to stop', 50, 50);
556
+ * } else {
557
+ * text('Click to loop', 50, 50);
558
+ * }
559
+ * }
560
+ *
561
+ * // Adjust playback when the user presses the mouse.
562
+ * function mousePressed() {
563
+ * if (isLooping === true) {
564
+ * // If the beat is looping, stop it.
565
+ * beat.stop();
566
+ * isLooping = false;
567
+ * } else {
568
+ * // If the beat is stopped, loop it.
569
+ * beat.loop();
570
+ * isLooping = true;
571
+ * }
572
+ * }
573
+ * </code>
574
+ * </div>
575
+ */
576
+ function loop(): void;
577
+
578
+ /**
579
+ * Stops the audio/video from playing in a loop.The media will stop when it finishes playing.
580
+ *
581
+ * @example <div>
582
+ * <code>
583
+ * let beat;
584
+ * let isPlaying = false;
585
+ *
586
+ * function setup() {
587
+ * createCanvas(100, 100);
588
+ *
589
+ * background(200);
590
+ *
591
+ * // Create a p5.MediaElement using createAudio().
592
+ * beat = createAudio('assets/beat.mp3');
593
+ *
594
+ * describe('The text "Click to play" written in black on a gray background. A beat plays when the user clicks. The beat stops when the user clicks again.');
595
+ * }
596
+ *
597
+ * function draw() {
598
+ * background(200);
599
+ *
600
+ * // Style the text.
601
+ * textAlign(CENTER);
602
+ * textSize(16);
603
+ *
604
+ * // Display different instructions based on playback.
605
+ * if (isPlaying === true) {
606
+ * text('Click to stop', 50, 50);
607
+ * } else {
608
+ * text('Click to play', 50, 50);
609
+ * }
610
+ * }
611
+ *
612
+ * // Adjust playback when the user presses the mouse.
613
+ * function mousePressed() {
614
+ * if (isPlaying === true) {
615
+ * // If the beat is playing, stop it.
616
+ * beat.stop();
617
+ * isPlaying = false;
618
+ * } else {
619
+ * // If the beat is stopped, play it.
620
+ * beat.play();
621
+ * isPlaying = true;
622
+ * }
623
+ * }
624
+ * </code>
625
+ * </div>
626
+ */
627
+ function noLoop(): void;
628
+
629
+ /**
630
+ * Sets the audio/video to play once it's loaded.The parameter, `shouldAutoplay`, is optional. Calling
631
+ * `media.autoplay()` without an argument causes the media to play
632
+ * automatically. If `true` is passed, as in `media.autoplay(true)`, the
633
+ * media will automatically play. If `false` is passed, as in
634
+ * `media.autoPlay(false)`, it won't play automatically.
635
+ *
636
+ * @param whether the element should autoplay.
637
+ * @example <div class='notest'>
638
+ * <code>
639
+ * let video;
640
+ *
641
+ * function setup() {
642
+ * noCanvas();
643
+ *
644
+ * // Call handleVideo() once the video loads.
645
+ * video = createVideo('assets/fingers.mov', handleVideo);
646
+ *
647
+ * describe('A video of fingers walking on a treadmill.');
648
+ * }
649
+ *
650
+ * // Set the video's size and play it.
651
+ * function handleVideo() {
652
+ * video.size(100, 100);
653
+ * video.autoplay();
654
+ * }
655
+ * </code>
656
+ * </div>
657
+ *
658
+ * <div class='notest'>
659
+ * <code>
660
+ * function setup() {
661
+ * noCanvas();
662
+ *
663
+ * // Load a video, but don't play it automatically.
664
+ * let video = createVideo('assets/fingers.mov', handleVideo);
665
+ *
666
+ * // Play the video when the user clicks on it.
667
+ * video.mousePressed(handlePress);
668
+ *
669
+ * describe('An image of fingers on a treadmill. They start walking when the user double-clicks on them.');
670
+ * }
671
+ * </code>
672
+ * </div>
673
+ *
674
+ * // Set the video's size and playback mode.
675
+ * function handleVideo() {
676
+ * video.size(100, 100);
677
+ * video.autoplay(false);
678
+ * }
679
+ *
680
+ * // Play the video.
681
+ * function handleClick() {
682
+ * video.play();
683
+ * }
684
+ */
685
+ function autoplay(val: any, shouldAutoplay?: boolean): void;
686
+
687
+ /**
688
+ * Sets the audio/video volume.Calling `media.volume()` without an argument returns the current volume
689
+ * as a number in the range 0 (off) to 1 (maximum).The parameter, `val`, is optional. It's a number that sets the volume
690
+ * from 0 (off) to 1 (maximum). For example, calling `media.volume(0.5)`
691
+ * sets the volume to half of its maximum.
692
+ *
693
+ * @return current volume.
694
+ * @example <div>
695
+ * <code>
696
+ * let dragon;
697
+ *
698
+ * function setup() {
699
+ * createCanvas(100, 100);
700
+ *
701
+ * // Create a p5.MediaElement using createAudio().
702
+ * dragon = createAudio('assets/lucky_dragons.mp3');
703
+ *
704
+ * // Show the default media controls.
705
+ * dragon.showControls();
706
+ *
707
+ * describe('The text "Volume: V" on a gray square with media controls beneath it. The number "V" oscillates between 0 and 1 as the music plays.');
708
+ * }
709
+ *
710
+ * function draw() {
711
+ * background(200);
712
+ *
713
+ * // Produce a number between 0 and 1.
714
+ * let n = 0.5 * sin(frameCount * 0.01) + 0.5;
715
+ *
716
+ * // Use n to set the volume.
717
+ * dragon.volume(n);
718
+ *
719
+ * // Get the current volume and display it.
720
+ * let v = dragon.volume();
721
+ *
722
+ * // Round v to 1 decimal place for display.
723
+ * v = round(v, 1);
724
+ *
725
+ * // Style the text.
726
+ * textAlign(CENTER);
727
+ * textSize(16);
728
+ *
729
+ * // Display the volume.
730
+ * text(`Volume: ${v}`, 50, 50);
731
+ * }
732
+ * </code>
733
+ * </div>
734
+ */
735
+ function volume(val: any): number;
736
+
737
+ /**
738
+ * @param volume between 0.0 and 1.0.
739
+ */
740
+ function volume(val: number): void;
741
+
742
+ /**
743
+ * Sets the audio/video playback speed.The parameter, `val`, is optional. It's a number that sets the playback
744
+ * speed. 1 plays the media at normal speed, 0.5 plays it at half speed, 2
745
+ * plays it at double speed, and so on. -1 plays the media at normal speed
746
+ * in reverse.Calling `media.speed()` returns the current speed as a number.Note: Not all browsers support backward playback. Even if they do,
747
+ * playback might not be smooth.
748
+ *
749
+ * @return current playback speed.
750
+ * @example <div>
751
+ * <code>
752
+ * let dragon;
753
+ *
754
+ * function setup() {
755
+ * createCanvas(100, 100);
756
+ *
757
+ * // Create a p5.MediaElement using createAudio().
758
+ * dragon = createAudio('assets/lucky_dragons.mp3');
759
+ *
760
+ * // Show the default media controls.
761
+ * dragon.showControls();
762
+ *
763
+ * describe('The text "Speed: S" on a gray square with media controls beneath it. The number "S" oscillates between 0 and 1 as the music plays.');
764
+ * }
765
+ *
766
+ * function draw() {
767
+ * background(200);
768
+ *
769
+ * // Produce a number between 0 and 2.
770
+ * let n = sin(frameCount * 0.01) + 1;
771
+ *
772
+ * // Use n to set the playback speed.
773
+ * dragon.speed(n);
774
+ *
775
+ * // Get the current speed and display it.
776
+ * let s = dragon.speed();
777
+ *
778
+ * // Round s to 1 decimal place for display.
779
+ * s = round(s, 1);
780
+ *
781
+ * // Style the text.
782
+ * textAlign(CENTER);
783
+ * textSize(16);
784
+ *
785
+ * // Display the speed.
786
+ * text(`Speed: ${s}`, 50, 50);
787
+ * }
788
+ * </code>
789
+ */
790
+ function speed(val: any): number;
791
+
792
+ /**
793
+ * @param speed multiplier for playback.
794
+ */
795
+ function speed(val: any, speed: number): void;
796
+
797
+ /**
798
+ * Sets the media element's playback time.The parameter, `time`, is optional. It's a number that specifies the
799
+ * time, in seconds, to jump to when playback begins.Calling `media.time()` without an argument returns the number of seconds
800
+ * the audio/video has played.Note: Time resets to 0 when looping media restarts.
801
+ *
802
+ * @return current time (in seconds).
803
+ * @example <div>
804
+ * <code>
805
+ * let dragon;
806
+ *
807
+ * function setup() {
808
+ * createCanvas(100, 100);
809
+ *
810
+ * // Create a p5.MediaElement using createAudio().
811
+ * dragon = createAudio('assets/lucky_dragons.mp3');
812
+ *
813
+ * // Show the default media controls.
814
+ * dragon.showControls();
815
+ *
816
+ * describe('The text "S seconds" on a gray square with media controls beneath it. The number "S" increases as the song plays.');
817
+ * }
818
+ *
819
+ * function draw() {
820
+ * background(200);
821
+ *
822
+ * // Get the current playback time.
823
+ * let s = dragon.time();
824
+ *
825
+ * // Round s to 1 decimal place for display.
826
+ * s = round(s, 1);
827
+ *
828
+ * // Style the text.
829
+ * textAlign(CENTER);
830
+ * textSize(16);
831
+ *
832
+ * // Display the playback time.
833
+ * text(`${s} seconds`, 50, 50);
834
+ * }
835
+ * </code>
836
+ * </div>
837
+ *
838
+ * <div>
839
+ * <code>
840
+ * let dragon;
841
+ *
842
+ * function setup() {
843
+ * createCanvas(100, 100);
844
+ *
845
+ * // Create a p5.MediaElement using createAudio().
846
+ * dragon = createAudio('assets/lucky_dragons.mp3');
847
+ *
848
+ * // Show the default media controls.
849
+ * dragon.showControls();
850
+ *
851
+ * // Jump to 2 seconds to start.
852
+ * dragon.time(2);
853
+ *
854
+ * describe('The text "S seconds" on a gray square with media controls beneath it. The number "S" increases as the song plays.');
855
+ * }
856
+ *
857
+ * function draw() {
858
+ * background(200);
859
+ *
860
+ * // Get the current playback time.
861
+ * let s = dragon.time();
862
+ *
863
+ * // Round s to 1 decimal place for display.
864
+ * s = round(s, 1);
865
+ *
866
+ * // Style the text.
867
+ * textAlign(CENTER);
868
+ * textSize(16);
869
+ *
870
+ * // Display the playback time.
871
+ * text(`${s} seconds`, 50, 50);
872
+ * }
873
+ * </code>
874
+ * </div>
875
+ */
876
+ function time(val: any): number;
877
+
878
+ /**
879
+ * @param time to jump to (in seconds).
880
+ */
881
+ function time(val: any, time: number): void;
882
+
883
+ /**
884
+ * Returns the audio/video's duration in seconds.
885
+ *
886
+ * @return duration (in seconds).
887
+ * @example <div>
888
+ * <code>
889
+ * let dragon;
890
+ *
891
+ * function setup() {
892
+ * createCanvas(100, 100);
893
+ *
894
+ * background(200);
895
+ *
896
+ * // Create a p5.MediaElement using createAudio().
897
+ * dragon = createAudio('assets/lucky_dragons.mp3');
898
+ *
899
+ * // Show the default media controls.
900
+ * dragon.showControls();
901
+ *
902
+ * describe('The text "S seconds left" on a gray square with media controls beneath it. The number "S" decreases as the song plays.');
903
+ * }
904
+ *
905
+ * function draw() {
906
+ * background(200);
907
+ *
908
+ * // Calculate the time remaining.
909
+ * let s = dragon.duration() - dragon.time();
910
+ *
911
+ * // Round s to 1 decimal place for display.
912
+ * s = round(s, 1);
913
+ *
914
+ * // Style the text.
915
+ * textAlign(CENTER);
916
+ * textSize(16);
917
+ *
918
+ * // Display the time remaining.
919
+ * text(`${s} seconds left`, 50, 50);
920
+ * }
921
+ * </code>
922
+ * </div>
923
+ */
924
+ function duration(): number;
925
+
926
+ /**
927
+ * Calls a function when the audio/video reaches the end of its playback.The element is passed as an argument to the callback function.Note: The function won't be called if the media is looping.
928
+ *
929
+ * @param function to call when playback ends.
930
+ * The `p5.MediaElement` is passed as
931
+ * the argument.
932
+ * @example <div>
933
+ * <code>
934
+ * let beat;
935
+ * let isPlaying = false;
936
+ * let isDone = false;
937
+ *
938
+ * function setup() {
939
+ * createCanvas(100, 100);
940
+ *
941
+ * // Create a p5.MediaElement using createAudio().
942
+ * beat = createAudio('assets/beat.mp3');
943
+ *
944
+ * // Call handleEnd() when the beat finishes.
945
+ * beat.onended(handleEnd);
946
+ *
947
+ * describe('The text "Click to play" written in black on a gray square. A beat plays when the user clicks. The text "Done!" appears when the beat finishes playing.');
948
+ * }
949
+ *
950
+ * function draw() {
951
+ * background(200);
952
+ *
953
+ * // Style the text.
954
+ * textAlign(CENTER);
955
+ * textSize(16);
956
+ *
957
+ * // Display different messages based on playback.
958
+ * if (isDone === true) {
959
+ * text('Done!', 50, 50);
960
+ * } else if (isPlaying === false) {
961
+ * text('Click to play', 50, 50);
962
+ * } else {
963
+ * text('Playing...', 50, 50);
964
+ * }
965
+ * }
966
+ *
967
+ * // Play the beat when the user presses the mouse.
968
+ * function mousePressed() {
969
+ * if (isPlaying === false) {
970
+ * isPlaying = true;
971
+ * beat.play();
972
+ * }
973
+ * }
974
+ *
975
+ * // Set isDone when playback ends.
976
+ * function handleEnd() {
977
+ * isDone = false;
978
+ * }
979
+ * </code>
980
+ * </div>
981
+ */
982
+ function onended(callback: Function): void;
983
+
984
+ /**
985
+ * Sends the element's audio to an output.The parameter, `audioNode`, can be an `AudioNode` or an object from the
986
+ * `p5.sound` library.If no element is provided, as in `myElement.connect()`, the element
987
+ * connects to the main output. All connections are removed by the
988
+ * `.disconnect()` method.Note: This method is meant to be used with the p5.sound.js addon library.
989
+ *
990
+ * @param AudioNode from the Web Audio API,
991
+ * or an object from the p5.sound library
992
+ */
993
+ function connect(obj: any, audioNode: AudioNode | object): void;
994
+
995
+ /**
996
+ * Disconnect all Web Audio routing, including to the main output.This is useful if you want to re-route the output through audio effects,
997
+ * for example.
998
+ *
999
+ */
1000
+ function disconnect(): void;
1001
+
1002
+ /**
1003
+ * Show the default
1004
+ * HTMLMediaElement
1005
+ * controls.Note: The controls vary between web browsers.
1006
+ *
1007
+ * @example <div>
1008
+ * <code>
1009
+ * function setup() {
1010
+ * createCanvas(100, 100);
1011
+ *
1012
+ * background('cornflowerblue');
1013
+ *
1014
+ * // Style the text.
1015
+ * textAlign(CENTER);
1016
+ * textSize(50);
1017
+ *
1018
+ * // Display a dragon.
1019
+ * text('🐉', 50, 50);
1020
+ *
1021
+ * // Create a p5.MediaElement using createAudio().
1022
+ * let dragon = createAudio('assets/lucky_dragons.mp3');
1023
+ *
1024
+ * // Show the default media controls.
1025
+ * dragon.showControls();
1026
+ *
1027
+ * describe('A dragon emoji, 🐉, drawn in the center of a blue square. A song plays in the background. Audio controls are displayed beneath the canvas.');
1028
+ * }
1029
+ * </code>
1030
+ * </div>
1031
+ */
1032
+ function showControls(): void;
1033
+
1034
+ /**
1035
+ * Hide the default
1036
+ * HTMLMediaElement
1037
+ * controls.
1038
+ *
1039
+ * @example <div>
1040
+ * <code>
1041
+ * let dragon;
1042
+ * let isHidden = false;
1043
+ *
1044
+ * function setup() {
1045
+ * createCanvas(100, 100);
1046
+ *
1047
+ * // Create a p5.MediaElement using createAudio().
1048
+ * dragon = createAudio('assets/lucky_dragons.mp3');
1049
+ *
1050
+ * // Show the default media controls.
1051
+ * dragon.showControls();
1052
+ *
1053
+ * describe('The text "Double-click to hide controls" written in the middle of a gray square. A song plays in the background. Audio controls are displayed beneath the canvas. The controls appear/disappear when the user double-clicks the square.');
1054
+ * }
1055
+ *
1056
+ * function draw() {
1057
+ * background(200);
1058
+ *
1059
+ * // Style the text.
1060
+ * textAlign(CENTER);
1061
+ *
1062
+ * // Display a different message when controls are hidden or shown.
1063
+ * if (isHidden === true) {
1064
+ * text('Double-click to show controls', 10, 20, 80, 80);
1065
+ * } else {
1066
+ * text('Double-click to hide controls', 10, 20, 80, 80);
1067
+ * }
1068
+ * }
1069
+ *
1070
+ * // Show/hide controls based on a double-click.
1071
+ * function doubleClicked() {
1072
+ * if (isHidden === true) {
1073
+ * dragon.showControls();
1074
+ * isHidden = false;
1075
+ * } else {
1076
+ * dragon.hideControls();
1077
+ * isHidden = true;
1078
+ * }
1079
+ * }
1080
+ * </code>
1081
+ * </div>
1082
+ */
1083
+ function hideControls(): void;
1084
+
1085
+ /**
1086
+ * Schedules a function to call when the audio/video reaches a specific time
1087
+ * during its playback.The first parameter, `time`, is the time, in seconds, when the function
1088
+ * should run. This value is passed to `callback` as its first argument.The second parameter, `callback`, is the function to call at the specified
1089
+ * cue time.The third parameter, `value`, is optional and can be any type of value.
1090
+ * `value` is passed to `callback`.Calling `media.addCue()` returns an ID as a string. This is useful for
1091
+ * removing the cue later.
1092
+ *
1093
+ * @param cue time to run the callback function.
1094
+ * @param function to call at the cue time.
1095
+ * @param object to pass as the argument to
1096
+ * `callback`.
1097
+ * @return id ID of this cue,
1098
+ * useful for `media.removeCue(id)`.
1099
+ * @example <div>
1100
+ * <code>
1101
+ * function setup() {
1102
+ * createCanvas(100, 100);
1103
+ *
1104
+ * // Create a p5.MediaElement using createAudio().
1105
+ * let beat = createAudio('assets/beat.mp3');
1106
+ *
1107
+ * // Play the beat in a loop.
1108
+ * beat.loop();
1109
+ *
1110
+ * // Schedule a few events.
1111
+ * beat.addCue(0, changeBackground, 'red');
1112
+ * beat.addCue(2, changeBackground, 'deeppink');
1113
+ * beat.addCue(4, changeBackground, 'orchid');
1114
+ * beat.addCue(6, changeBackground, 'lavender');
1115
+ *
1116
+ * describe('A red square with a beat playing in the background. Its color changes every 2 seconds while the audio plays.');
1117
+ * }
1118
+ *
1119
+ * // Change the background color.
1120
+ * function changeBackground(c) {
1121
+ * background(c);
1122
+ * }
1123
+ * </code>
1124
+ * </div>
1125
+ */
1126
+ function addCue(time: number, callback: Function, val: any, value?: object): number;
1127
+
1128
+ /**
1129
+ * Removes a callback based on its ID.
1130
+ *
1131
+ * @param ID of the cue, created by `media.addCue()`.
1132
+ * @example <div>
1133
+ * <code>
1134
+ * let lavenderID;
1135
+ * let isRemoved = false;
1136
+ *
1137
+ * function setup() {
1138
+ * createCanvas(100, 100);
1139
+ *
1140
+ * // Create a p5.MediaElement using createAudio().
1141
+ * let beat = createAudio('assets/beat.mp3');
1142
+ *
1143
+ * // Play the beat in a loop.
1144
+ * beat.loop();
1145
+ *
1146
+ * // Schedule a few events.
1147
+ * beat.addCue(0, changeBackground, 'red');
1148
+ * beat.addCue(2, changeBackground, 'deeppink');
1149
+ * beat.addCue(4, changeBackground, 'orchid');
1150
+ *
1151
+ * // Record the ID of the "lavender" callback.
1152
+ * lavenderID = beat.addCue(6, changeBackground, 'lavender');
1153
+ *
1154
+ * describe('The text "Double-click to remove lavender." written on a red square. The color changes every 2 seconds while the audio plays. The lavender option is removed when the user double-clicks the square.');
1155
+ * }
1156
+ *
1157
+ * function draw() {
1158
+ * background(200);
1159
+ *
1160
+ * // Display different instructions based on the available callbacks.
1161
+ * if (isRemoved === false) {
1162
+ * text('Double-click to remove lavender.', 10, 10, 80, 80);
1163
+ * } else {
1164
+ * text('No more lavender.', 10, 10, 80, 80);
1165
+ * }
1166
+ * }
1167
+ *
1168
+ * // Change the background color.
1169
+ * function changeBackground(c) {
1170
+ * background(c);
1171
+ * }
1172
+ *
1173
+ * // Remove the lavender color-change cue when the user double-clicks.
1174
+ * function doubleClicked() {
1175
+ * if (isRemoved === false) {
1176
+ * beat.removeCue(lavenderID);
1177
+ * isRemoved = true;
1178
+ * }
1179
+ * }
1180
+ * </code>
1181
+ * </div>
1182
+ */
1183
+ function removeCue(id: number): void;
1184
+
1185
+ /**
1186
+ * Removes all functions scheduled with `media.addCue()`.
1187
+ *
1188
+ * @example <div>
1189
+ * <code>
1190
+ * let isChanging = true;
1191
+ *
1192
+ * function setup() {
1193
+ * createCanvas(100, 100);
1194
+ *
1195
+ * background(200);
1196
+ *
1197
+ * // Create a p5.MediaElement using createAudio().
1198
+ * let beat = createAudio('assets/beat.mp3');
1199
+ *
1200
+ * // Play the beat in a loop.
1201
+ * beat.loop();
1202
+ *
1203
+ * // Schedule a few events.
1204
+ * beat.addCue(0, changeBackground, 'red');
1205
+ * beat.addCue(2, changeBackground, 'deeppink');
1206
+ * beat.addCue(4, changeBackground, 'orchid');
1207
+ * beat.addCue(6, changeBackground, 'lavender');
1208
+ *
1209
+ * describe('The text "Double-click to stop changing." written on a square. The color changes every 2 seconds while the audio plays. The color stops changing when the user double-clicks the square.');
1210
+ * }
1211
+ *
1212
+ * function draw() {
1213
+ * background(200);
1214
+ *
1215
+ * // Display different instructions based on the available callbacks.
1216
+ * if (isChanging === true) {
1217
+ * text('Double-click to stop changing.', 10, 10, 80, 80);
1218
+ * } else {
1219
+ * text('No more changes.', 10, 10, 80, 80);
1220
+ * }
1221
+ * }
1222
+ *
1223
+ * // Change the background color.
1224
+ * function changeBackground(c) {
1225
+ * background(c);
1226
+ * }
1227
+ *
1228
+ * // Remove cued functions and stop changing colors when the user
1229
+ * // double-clicks.
1230
+ * function doubleClicked() {
1231
+ * if (isChanging === true) {
1232
+ * beat.clearCues();
1233
+ * isChanging = false;
1234
+ * }
1235
+ * }
1236
+ * </code>
1237
+ * </div>
1238
+ */
1239
+ function clearCues(): void;
1240
+
1241
+ /**
1242
+ * VIDEO STUFF *
1243
+ *
1244
+ */
1245
+ function createMedia(pInst: any, type: any, src: any, callback: any): void;
1246
+
1247
+ }
1248
+
1249
+ export default function p5_MediaElement(p5: any, fn: any): void;