p5 2.0.1 → 2.0.3

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 (160) hide show
  1. package/dist/accessibility/color_namer.js +5 -5
  2. package/dist/accessibility/describe.js +10 -0
  3. package/dist/accessibility/index.js +5 -5
  4. package/dist/accessibility/outputs.js +21 -0
  5. package/dist/app.js +5 -5
  6. package/dist/color/color_conversion.js +5 -5
  7. package/dist/color/creating_reading.js +1 -1
  8. package/dist/color/index.js +2 -2
  9. package/dist/color/p5.Color.js +1 -1
  10. package/dist/color/setting.js +2 -2
  11. package/dist/{constants-C-g_eAdC.js → constants-BRcElHU3.js} +19 -3
  12. package/dist/core/constants.js +1 -1
  13. package/dist/core/environment.js +6 -5
  14. package/dist/core/friendly_errors/fes_core.js +1 -1
  15. package/dist/core/friendly_errors/index.js +1 -1
  16. package/dist/core/friendly_errors/param_validator.js +46 -93
  17. package/dist/core/friendly_errors/sketch_reader.js +5 -5
  18. package/dist/core/friendly_errors/sketch_verifier.js +1 -1
  19. package/dist/core/friendly_errors/validate_params.js +5 -5
  20. package/dist/core/helpers.js +1 -1
  21. package/dist/core/init.js +5 -5
  22. package/dist/core/legacy.js +5 -5
  23. package/dist/core/main.js +5 -5
  24. package/dist/core/p5.Graphics.js +4 -4
  25. package/dist/core/p5.Renderer.js +3 -3
  26. package/dist/core/p5.Renderer2D.js +5 -5
  27. package/dist/core/rendering.js +4 -4
  28. package/dist/{creating_reading-D4AAKRbx.js → creating_reading-Cr8L2Jnm.js} +2 -2
  29. package/dist/dom/dom.js +10 -10
  30. package/dist/dom/index.js +2 -2
  31. package/dist/dom/p5.Element.js +2 -2
  32. package/dist/dom/p5.MediaElement.js +2 -2
  33. package/dist/events/acceleration.js +24 -24
  34. package/dist/events/keyboard.js +11 -6
  35. package/dist/image/const.js +1 -1
  36. package/dist/image/filterRenderer2D.js +4 -4
  37. package/dist/image/image.js +4 -4
  38. package/dist/image/index.js +4 -4
  39. package/dist/image/loading_displaying.js +4 -4
  40. package/dist/image/p5.Image.js +3 -3
  41. package/dist/image/pixels.js +1 -0
  42. package/dist/io/files.js +4 -4
  43. package/dist/io/index.js +4 -4
  44. package/dist/io/p5.TableRow.js +2 -2
  45. package/dist/{main-s72KWcUy.js → main-BKN5yFoS.js} +12 -9
  46. package/dist/math/Matrices/Matrix.js +1 -1
  47. package/dist/math/Matrices/MatrixNumjs.js +1 -1
  48. package/dist/math/index.js +1 -1
  49. package/dist/math/math.js +1 -1
  50. package/dist/math/p5.Matrix.js +1 -1
  51. package/dist/math/p5.Vector.js +1 -1
  52. package/dist/math/trigonometry.js +1 -1
  53. package/dist/{p5.Renderer-CwAYZOC2.js → p5.Renderer-R23xoC7s.js} +5 -5
  54. package/dist/{rendering--aAe5aq3.js → rendering-CvUVN-Vb.js} +101 -66
  55. package/dist/shape/2d_primitives.js +1 -1
  56. package/dist/shape/attributes.js +1 -1
  57. package/dist/shape/custom_shapes.js +2 -2
  58. package/dist/shape/index.js +2 -2
  59. package/dist/type/index.js +3 -3
  60. package/dist/type/p5.Font.js +3 -5
  61. package/dist/type/textCore.js +4 -4
  62. package/dist/webgl/3d_primitives.js +4 -4
  63. package/dist/webgl/GeometryBuilder.js +1 -1
  64. package/dist/webgl/ShapeBuilder.js +1 -1
  65. package/dist/webgl/index.js +4 -4
  66. package/dist/webgl/interaction.js +1 -1
  67. package/dist/webgl/light.js +4 -4
  68. package/dist/webgl/loading.js +5 -4
  69. package/dist/webgl/material.js +4 -4
  70. package/dist/webgl/p5.Camera.js +4 -4
  71. package/dist/webgl/p5.Framebuffer.js +4 -4
  72. package/dist/webgl/p5.Geometry.js +1 -1
  73. package/dist/webgl/p5.Quat.js +1 -1
  74. package/dist/webgl/p5.RendererGL.js +4 -4
  75. package/dist/webgl/p5.Shader.js +4 -4
  76. package/dist/webgl/p5.Texture.js +4 -4
  77. package/dist/webgl/text.js +32 -34
  78. package/lib/p5.esm.js +289 -247
  79. package/lib/p5.js +289 -247
  80. package/lib/p5.min.js +1 -1
  81. package/package.json +1 -2
  82. package/types/accessibility/color_namer.d.ts +8 -0
  83. package/types/accessibility/describe.d.ts +184 -0
  84. package/types/accessibility/gridOutput.d.ts +8 -0
  85. package/types/accessibility/outputs.d.ts +235 -0
  86. package/types/accessibility/textOutput.d.ts +8 -0
  87. package/types/color/color_conversion.d.ts +47 -0
  88. package/types/color/creating_reading.d.ts +1348 -0
  89. package/types/color/p5.Color.d.ts +1070 -0
  90. package/types/color/setting.d.ts +2085 -0
  91. package/types/core/constants.d.ts +341 -0
  92. package/types/core/environment.d.ts +668 -0
  93. package/types/core/friendly_errors/fes_core.d.ts +8 -0
  94. package/types/core/friendly_errors/file_errors.d.ts +8 -0
  95. package/types/core/friendly_errors/param_validator.d.ts +30 -0
  96. package/types/core/friendly_errors/sketch_reader.d.ts +8 -0
  97. package/types/core/friendly_errors/stacktrace.d.ts +11 -0
  98. package/types/core/friendly_errors/validate_params.d.ts +8 -0
  99. package/types/core/helpers.d.ts +8 -0
  100. package/types/core/legacy.d.ts +8 -0
  101. package/types/core/main.d.ts +5999 -0
  102. package/types/core/p5.Graphics.d.ts +484 -0
  103. package/types/core/p5.Renderer.d.ts +14 -0
  104. package/types/core/reference.d.ts +8 -0
  105. package/types/core/rendering.d.ts +481 -0
  106. package/types/core/structure.d.ts +492 -0
  107. package/types/core/transform.d.ts +1638 -0
  108. package/types/data/local_storage.d.ts +323 -0
  109. package/types/dom/dom.d.ts +1295 -0
  110. package/types/dom/p5.Element.d.ts +2011 -0
  111. package/types/dom/p5.File.d.ts +13 -0
  112. package/types/dom/p5.MediaElement.d.ts +1249 -0
  113. package/types/events/acceleration.d.ts +193 -0
  114. package/types/events/keyboard.d.ts +501 -0
  115. package/types/events/pointer.d.ts +782 -0
  116. package/types/global.d.ts +5544 -0
  117. package/types/image/filterRenderer2D.d.ts +54 -0
  118. package/types/image/image.d.ts +326 -0
  119. package/types/image/loading_displaying.d.ts +580 -0
  120. package/types/image/p5.Image.d.ts +5882 -0
  121. package/types/image/pixels.d.ts +832 -0
  122. package/types/io/files.d.ts +1447 -0
  123. package/types/io/p5.Table.d.ts +1247 -0
  124. package/types/io/p5.TableRow.d.ts +343 -0
  125. package/types/io/p5.XML.d.ts +1188 -0
  126. package/types/math/Matrices/Matrix.d.ts +1029 -0
  127. package/types/math/Matrices/MatrixNumjs.d.ts +8 -0
  128. package/types/math/calculation.d.ts +923 -0
  129. package/types/math/math.d.ts +90 -0
  130. package/types/math/noise.d.ts +311 -0
  131. package/types/math/p5.Matrix.d.ts +8 -0
  132. package/types/math/p5.Vector.d.ts +3416 -0
  133. package/types/math/random.d.ts +267 -0
  134. package/types/math/trigonometry.d.ts +663 -0
  135. package/types/p5.d.ts +6666 -0
  136. package/types/shape/2d_primitives.d.ts +1033 -0
  137. package/types/shape/attributes.d.ts +466 -0
  138. package/types/shape/curves.d.ts +740 -0
  139. package/types/shape/custom_shapes.d.ts +888 -0
  140. package/types/shape/vertex.d.ts +1141 -0
  141. package/types/type/p5.Font.d.ts +575 -0
  142. package/types/type/textCore.d.ts +1198 -0
  143. package/types/utilities/conversion.d.ts +894 -0
  144. package/types/utilities/time_date.d.ts +295 -0
  145. package/types/utilities/utility_functions.d.ts +587 -0
  146. package/types/webgl/3d_primitives.d.ts +1432 -0
  147. package/types/webgl/ShaderGenerator.d.ts +8 -0
  148. package/types/webgl/interaction.d.ts +371 -0
  149. package/types/webgl/light.d.ts +1184 -0
  150. package/types/webgl/loading.d.ts +482 -0
  151. package/types/webgl/material.d.ts +2656 -0
  152. package/types/webgl/p5.Camera.d.ts +3023 -0
  153. package/types/webgl/p5.DataArray.d.ts +61 -0
  154. package/types/webgl/p5.Framebuffer.d.ts +760 -0
  155. package/types/webgl/p5.Geometry.d.ts +1191 -0
  156. package/types/webgl/p5.Quat.d.ts +45 -0
  157. package/types/webgl/p5.RendererGL.d.ts +234 -0
  158. package/types/webgl/p5.Shader.d.ts +660 -0
  159. package/types/webgl/p5.Texture.d.ts +61 -0
  160. package/types/webgl/text.d.ts +74 -0
@@ -0,0 +1,2656 @@
1
+ // This file is auto-generated from JSDoc documentation
2
+
3
+ import p5 from 'p5';
4
+ import { Color } from '../color/p5.Color';
5
+
6
+ declare module 'p5' {
7
+ /**
8
+ * Loads vertex and fragment shaders to create a
9
+ * p5.Shader object.Shaders are programs that run on the graphics processing unit (GPU). They
10
+ * can process many pixels at the same time, making them fast for many
11
+ * graphics tasks. They’re written in a language called
12
+ * GLSL
13
+ * and run along with the rest of the code in a sketch.Once the p5.Shader object is created, it can be
14
+ * used with the shader() function, as in
15
+ * `shader(myShader)`. A shader program consists of two files, a vertex shader
16
+ * and a fragment shader. The vertex shader affects where 3D geometry is drawn
17
+ * on the screen and the fragment shader affects color.`loadShader()` loads the vertex and fragment shaders from their `.vert` and
18
+ * `.frag` files. For example, calling
19
+ * `loadShader('assets/shader.vert', 'assets/shader.frag')` loads both
20
+ * required shaders and returns a p5.Shader object.The third parameter, `successCallback`, is optional. If a function is
21
+ * passed, it will be called once the shader has loaded. The callback function
22
+ * can use the new p5.Shader object as its
23
+ * parameter. The return value of the `successCallback()` function will be used
24
+ * as the final return value of `loadShader()`.The fourth parameter, `failureCallback`, is also optional. If a function is
25
+ * passed, it will be called if the shader fails to load. The callback
26
+ * function can use the event error as its parameter. The return value of the `
27
+ * failureCallback()` function will be used as the final return value of `loadShader()`.This function returns a `Promise` and should be used in an `async` setup with
28
+ * `await`. See the examples for the usage syntax.Note: Shaders can only be used in WebGL mode.
29
+ *
30
+ * @param path of the vertex shader to be loaded.
31
+ * @param path of the fragment shader to be loaded.
32
+ * @param function to call once the shader is loaded. Can be passed the
33
+ * <a href="#/p5.Shader">p5.Shader</a> object.
34
+ * @param function to call if the shader fails to load. Can be passed an
35
+ * `Error` event object.
36
+ * @return new shader created from the vertex and fragment shader files.
37
+ * @example <div modernizr='webgl'>
38
+ * <code>
39
+ * // Note: A "uniform" is a global variable within a shader program.
40
+ *
41
+ * let mandelbrot;
42
+ *
43
+ * // Load the shader and create a p5.Shader object.
44
+ * async function setup() {
45
+ * mandelbrot = await loadShader('assets/shader.vert', 'assets/shader.frag');
46
+ *
47
+ * createCanvas(100, 100, WEBGL);
48
+ *
49
+ * // Compile and apply the p5.Shader object.
50
+ * shader(mandelbrot);
51
+ *
52
+ * // Set the shader uniform p to an array.
53
+ * mandelbrot.setUniform('p', [-0.74364388703, 0.13182590421]);
54
+ *
55
+ * // Set the shader uniform r to the value 1.5.
56
+ * mandelbrot.setUniform('r', 1.5);
57
+ *
58
+ * // Add a quad as a display surface for the shader.
59
+ * quad(-1, -1, 1, -1, 1, 1, -1, 1);
60
+ *
61
+ * describe('A black fractal image on a magenta background.');
62
+ * }
63
+ * </code>
64
+ * </div>
65
+ *
66
+ * <div>
67
+ * <code>
68
+ * // Note: A "uniform" is a global variable within a shader program.
69
+ *
70
+ * let mandelbrot;
71
+ *
72
+ * // Load the shader and create a p5.Shader object.
73
+ * async function setup() {
74
+ * mandelbrot = await loadShader('assets/shader.vert', 'assets/shader.frag');
75
+ *
76
+ * createCanvas(100, 100, WEBGL);
77
+ *
78
+ * // Use the p5.Shader object.
79
+ * shader(mandelbrot);
80
+ *
81
+ * // Set the shader uniform p to an array.
82
+ * mandelbrot.setUniform('p', [-0.74364388703, 0.13182590421]);
83
+ *
84
+ * describe('A fractal image zooms in and out of focus.');
85
+ * }
86
+ *
87
+ * function draw() {
88
+ * // Set the shader uniform r to a value that oscillates between 0 and 2.
89
+ * mandelbrot.setUniform('r', sin(frameCount * 0.01) + 1);
90
+ *
91
+ * // Add a quad as a display surface for the shader.
92
+ * quad(-1, -1, 1, -1, 1, 1, -1, 1);
93
+ * }
94
+ * </code>
95
+ * </div>
96
+ */
97
+ function loadShader(vertFilename: string | Request, fragFilename: string | Request, successCallback?: Function, failureCallback?: Function): Promise<p5.Shader>;
98
+
99
+ /**
100
+ * Creates a new p5.Shader object.Shaders are programs that run on the graphics processing unit (GPU). They
101
+ * can process many pixels at the same time, making them fast for many
102
+ * graphics tasks. They’re written in a language called
103
+ * GLSL
104
+ * and run along with the rest of the code in a sketch.Once the p5.Shader object is created, it can be
105
+ * used with the shader() function, as in
106
+ * `shader(myShader)`. A shader program consists of two parts, a vertex shader
107
+ * and a fragment shader. The vertex shader affects where 3D geometry is drawn
108
+ * on the screen and the fragment shader affects color.The first parameter, `vertSrc`, sets the vertex shader. It’s a string that
109
+ * contains the vertex shader program written in GLSL.The second parameter, `fragSrc`, sets the fragment shader. It’s a string
110
+ * that contains the fragment shader program written in GLSL.A shader can optionally describe which are functions in GLSL that
111
+ * users may choose to provide to customize the behavior of the shader using the
112
+ * `modify()` method of `p5.Shader`. These are added by
113
+ * describing the hooks in a third parameter, `options`, and referencing the hooks in
114
+ * your `vertSrc` or `fragSrc`. Hooks for the vertex or fragment shader are described under
115
+ * the `vertex` and `fragment` keys of `options`. Each one is an object. where each key is
116
+ * the type and name of a hook function, and each value is a string with the
117
+ * parameter list and default implementation of the hook. For example, to let users
118
+ * optionally run code at the start of the vertex shader, the options object could
119
+ * include:`{
120
+ * vertex: {
121
+ * 'void beforeVertex': '() {}'
122
+ * }
123
+ * }`Then, in your vertex shader source, you can run a hook by calling a function
124
+ * with the same name prefixed by `HOOK_`. If you want to check if the default
125
+ * hook has been replaced, maybe to avoid extra overhead, you can check if the
126
+ * same name prefixed by `AUGMENTED_HOOK_` has been defined:`void main() {
127
+ * // In most cases, just calling the hook is fine:
128
+ * HOOK_beforeVertex();
129
+ *
130
+ * // Alternatively, for more efficiency:
131
+ * #ifdef AUGMENTED_HOOK_beforeVertex
132
+ * HOOK_beforeVertex();
133
+ * #endif
134
+ *
135
+ * // Add the rest of your shader code here!
136
+ * }`Note: Only filter shaders can be used in 2D mode. All shaders can be used
137
+ * in WebGL mode.
138
+ *
139
+ * @param source code for the vertex shader.
140
+ * @param source code for the fragment shader.
141
+ * @param An optional object describing how this shader can
142
+ * be augmented with hooks. It can include:
143
+ * - `vertex`: An object describing the available vertex shader hooks.
144
+ * - `fragment`: An object describing the available frament shader hooks.
145
+ * @returns new shader object created from the
146
+ * vertex and fragment shaders.
147
+ * @example <div modernizr='webgl'>
148
+ * <code>
149
+ * // Note: A "uniform" is a global variable within a shader program.
150
+ *
151
+ * // Create a string with the vertex shader program.
152
+ * // The vertex shader is called for each vertex.
153
+ * let vertSrc = `
154
+ * precision highp float;
155
+ * uniform mat4 uModelViewMatrix;
156
+ * uniform mat4 uProjectionMatrix;
157
+ * attribute vec3 aPosition;
158
+ * attribute vec2 aTexCoord;
159
+ * varying vec2 vTexCoord;
160
+ *
161
+ * void main() {
162
+ * vTexCoord = aTexCoord;
163
+ * vec4 positionVec4 = vec4(aPosition, 1.0);
164
+ * gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;
165
+ * }
166
+ * `;
167
+ *
168
+ * // Create a string with the fragment shader program.
169
+ * // The fragment shader is called for each pixel.
170
+ * let fragSrc = `
171
+ * precision highp float;
172
+ *
173
+ * void main() {
174
+ * // Set each pixel's RGBA value to yellow.
175
+ * gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);
176
+ * }
177
+ * `;
178
+ *
179
+ * function setup() {
180
+ * createCanvas(100, 100, WEBGL);
181
+ *
182
+ * // Create a p5.Shader object.
183
+ * let shaderProgram = createShader(vertSrc, fragSrc);
184
+ *
185
+ * // Compile and apply the p5.Shader object.
186
+ * shader(shaderProgram);
187
+ *
188
+ * // Style the drawing surface.
189
+ * noStroke();
190
+ *
191
+ * // Add a plane as a drawing surface.
192
+ * plane(100, 100);
193
+ *
194
+ * describe('A yellow square.');
195
+ * }
196
+ * </code>
197
+ * </div>
198
+ *
199
+ * <div>
200
+ * <code>
201
+ * // Note: A "uniform" is a global variable within a shader program.
202
+ *
203
+ * // Create a string with the vertex shader program.
204
+ * // The vertex shader is called for each vertex.
205
+ * let vertSrc = `
206
+ * precision highp float;
207
+ * uniform mat4 uModelViewMatrix;
208
+ * uniform mat4 uProjectionMatrix;
209
+ * attribute vec3 aPosition;
210
+ * attribute vec2 aTexCoord;
211
+ * varying vec2 vTexCoord;
212
+ *
213
+ * void main() {
214
+ * vTexCoord = aTexCoord;
215
+ * vec4 positionVec4 = vec4(aPosition, 1.0);
216
+ * gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;
217
+ * }
218
+ * `;
219
+ *
220
+ * // Create a string with the fragment shader program.
221
+ * // The fragment shader is called for each pixel.
222
+ * let fragSrc = `
223
+ * precision highp float;
224
+ * uniform vec2 p;
225
+ * uniform float r;
226
+ * const int numIterations = 500;
227
+ * varying vec2 vTexCoord;
228
+ *
229
+ * void main() {
230
+ * vec2 c = p + gl_FragCoord.xy * r;
231
+ * vec2 z = c;
232
+ * float n = 0.0;
233
+ *
234
+ * for (int i = numIterations; i > 0; i--) {
235
+ * if (z.x * z.x + z.y * z.y > 4.0) {
236
+ * n = float(i) / float(numIterations);
237
+ * break;
238
+ * }
239
+ * z = vec2(z.x * z.x - z.y * z.y, 2.0 * z.x * z.y) + c;
240
+ * }
241
+ *
242
+ * gl_FragColor = vec4(
243
+ * 0.5 - cos(n * 17.0) / 2.0,
244
+ * 0.5 - cos(n * 13.0) / 2.0,
245
+ * 0.5 - cos(n * 23.0) / 2.0,
246
+ * 1.0
247
+ * );
248
+ * }
249
+ * `;
250
+ *
251
+ * function setup() {
252
+ * createCanvas(100, 100, WEBGL);
253
+ *
254
+ * // Create a p5.Shader object.
255
+ * let mandelbrot = createShader(vertSrc, fragSrc);
256
+ *
257
+ * // Compile and apply the p5.Shader object.
258
+ * shader(mandelbrot);
259
+ *
260
+ * // Set the shader uniform p to an array.
261
+ * // p is the center point of the Mandelbrot image.
262
+ * mandelbrot.setUniform('p', [-0.74364388703, 0.13182590421]);
263
+ *
264
+ * // Set the shader uniform r to 0.005.
265
+ * // r is the size of the image in Mandelbrot-space.
266
+ * mandelbrot.setUniform('r', 0.005);
267
+ *
268
+ * // Style the drawing surface.
269
+ * noStroke();
270
+ *
271
+ * // Add a plane as a drawing surface.
272
+ * plane(100, 100);
273
+ *
274
+ * describe('A black fractal image on a magenta background.');
275
+ * }
276
+ * </code>
277
+ * </div>
278
+ *
279
+ * <div>
280
+ * <code>
281
+ * // Note: A "uniform" is a global variable within a shader program.
282
+ *
283
+ * // Create a string with the vertex shader program.
284
+ * // The vertex shader is called for each vertex.
285
+ * let vertSrc = `
286
+ * precision highp float;
287
+ * uniform mat4 uModelViewMatrix;
288
+ * uniform mat4 uProjectionMatrix;
289
+ *
290
+ * attribute vec3 aPosition;
291
+ * attribute vec2 aTexCoord;
292
+ * varying vec2 vTexCoord;
293
+ *
294
+ * void main() {
295
+ * vTexCoord = aTexCoord;
296
+ * vec4 positionVec4 = vec4(aPosition, 1.0);
297
+ * gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;
298
+ * }
299
+ * `;
300
+ *
301
+ * // Create a string with the fragment shader program.
302
+ * // The fragment shader is called for each pixel.
303
+ * let fragSrc = `
304
+ * precision highp float;
305
+ * uniform vec2 p;
306
+ * uniform float r;
307
+ * const int numIterations = 500;
308
+ * varying vec2 vTexCoord;
309
+ *
310
+ * void main() {
311
+ * vec2 c = p + gl_FragCoord.xy * r;
312
+ * vec2 z = c;
313
+ * float n = 0.0;
314
+ *
315
+ * for (int i = numIterations; i > 0; i--) {
316
+ * if (z.x * z.x + z.y * z.y > 4.0) {
317
+ * n = float(i) / float(numIterations);
318
+ * break;
319
+ * }
320
+ *
321
+ * z = vec2(z.x * z.x - z.y * z.y, 2.0 * z.x * z.y) + c;
322
+ * }
323
+ *
324
+ * gl_FragColor = vec4(
325
+ * 0.5 - cos(n * 17.0) / 2.0,
326
+ * 0.5 - cos(n * 13.0) / 2.0,
327
+ * 0.5 - cos(n * 23.0) / 2.0,
328
+ * 1.0
329
+ * );
330
+ * }
331
+ * `;
332
+ *
333
+ * let mandelbrot;
334
+ *
335
+ * function setup() {
336
+ * createCanvas(100, 100, WEBGL);
337
+ *
338
+ * // Create a p5.Shader object.
339
+ * mandelbrot = createShader(vertSrc, fragSrc);
340
+ *
341
+ * // Apply the p5.Shader object.
342
+ * shader(mandelbrot);
343
+ *
344
+ * // Set the shader uniform p to an array.
345
+ * // p is the center point of the Mandelbrot image.
346
+ * mandelbrot.setUniform('p', [-0.74364388703, 0.13182590421]);
347
+ *
348
+ * describe('A fractal image zooms in and out of focus.');
349
+ * }
350
+ *
351
+ * function draw() {
352
+ * // Set the shader uniform r to a value that oscillates
353
+ * // between 0 and 0.005.
354
+ * // r is the size of the image in Mandelbrot-space.
355
+ * let radius = 0.005 * (sin(frameCount * 0.01) + 1);
356
+ * mandelbrot.setUniform('r', radius);
357
+ *
358
+ * // Style the drawing surface.
359
+ * noStroke();
360
+ *
361
+ * // Add a plane as a drawing surface.
362
+ * plane(100, 100);
363
+ * }
364
+ * </code>
365
+ * </div>
366
+ *
367
+ * <div>
368
+ * <code>
369
+ * // A shader with hooks.
370
+ * let myShader;
371
+ *
372
+ * // A shader with modified hooks.
373
+ * let modifiedShader;
374
+ *
375
+ * // Create a string with the vertex shader program.
376
+ * // The vertex shader is called for each vertex.
377
+ * let vertSrc = `
378
+ * precision highp float;
379
+ * uniform mat4 uModelViewMatrix;
380
+ * uniform mat4 uProjectionMatrix;
381
+ *
382
+ * attribute vec3 aPosition;
383
+ * attribute vec2 aTexCoord;
384
+ *
385
+ * void main() {
386
+ * vec4 positionVec4 = vec4(aPosition, 1.0);
387
+ * gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;
388
+ * }
389
+ * `;
390
+ *
391
+ * // Create a fragment shader that uses a hook.
392
+ * let fragSrc = `
393
+ * precision highp float;
394
+ * void main() {
395
+ * // Let users override the color
396
+ * gl_FragColor = HOOK_getColor(vec4(1., 0., 0., 1.));
397
+ * }
398
+ * `;
399
+ *
400
+ * function setup() {
401
+ * createCanvas(50, 50, WEBGL);
402
+ *
403
+ * // Create a shader with hooks
404
+ * myShader = createShader(vertSrc, fragSrc, {
405
+ * fragment: {
406
+ * 'vec4 getColor': '(vec4 color) { return color; }'
407
+ * }
408
+ * });
409
+ *
410
+ * // Make a version of the shader with a hook overridden
411
+ * modifiedShader = myShader.modify({
412
+ * 'vec4 getColor': `(vec4 color) {
413
+ * return vec4(0., 0., 1., 1.);
414
+ * }`
415
+ * });
416
+ * }
417
+ *
418
+ * function draw() {
419
+ * noStroke();
420
+ *
421
+ * push();
422
+ * shader(myShader);
423
+ * translate(-width/3, 0);
424
+ * sphere(10);
425
+ * pop();
426
+ *
427
+ * push();
428
+ * shader(modifiedShader);
429
+ * translate(width/3, 0);
430
+ * sphere(10);
431
+ * pop();
432
+ * }
433
+ * </code>
434
+ * </div>
435
+ */
436
+ function createShader(vertSrc: string, fragSrc: string, options?: object): p5.Shader;
437
+
438
+ /**
439
+ * Creates and loads a filter shader from an external file.
440
+ *
441
+ * @param path to the fragment shader file
442
+ * @param callback to be called once the shader is
443
+ * loaded. Will be passed the
444
+ * <a href="#/p5.Shader">p5.Shader</a> object.
445
+ * @param callback to be called if there is an error
446
+ * loading the shader. Will be passed the
447
+ * error event.
448
+ * @return a promise that resolves with a shader object
449
+ * @example <div modernizr='webgl'>
450
+ * <code>
451
+ * let myShader;
452
+ *
453
+ * async function setup() {
454
+ * myShader = await loadFilterShader('assets/basic.frag');
455
+ * createCanvas(100, 100, WEBGL);
456
+ * noStroke();
457
+ * }
458
+ *
459
+ * function draw() {
460
+ * // shader() sets the active shader with our shader
461
+ * shader(myShader);
462
+ *
463
+ * // rect gives us some geometry on the screen
464
+ * rect(-50, -50, width, height);
465
+ * }
466
+ * </code>
467
+ * </div>
468
+ * @alt A rectangle with a shader applied to it.
469
+ */
470
+ function loadFilterShader(fragFilename: string, successCallback?: Function, failureCallback?: Function): Promise<p5.Shader>;
471
+
472
+ /**
473
+ * Creates a p5.Shader object to be used with the
474
+ * filter() function.`createFilterShader()` works like
475
+ * createShader() but has a default vertex
476
+ * shader included. `createFilterShader()` is intended to be used along with
477
+ * filter() for filtering the contents of a canvas.
478
+ * A filter shader will be applied to the whole canvas instead of just
479
+ * p5.Geometry objects.The parameter, `fragSrc`, sets the fragment shader. It’s a string that
480
+ * contains the fragment shader program written in
481
+ * GLSL.The p5.Shader object that's created has some
482
+ * uniforms that can be set:The p5.Shader that's created also provides
483
+ * `varying vec2 vTexCoord`, a coordinate with values between 0 and 1.
484
+ * `vTexCoord` describes where on the canvas the pixel will be drawn.For more info about filters and shaders, see Adam Ferriss' repo of shader examples
485
+ * or the Introduction to Shaders tutorial.
486
+ *
487
+ * @param source code for the fragment shader.
488
+ * @returns new shader object created from the fragment shader.
489
+ * @example <div modernizr='webgl'>
490
+ * <code>
491
+ * function setup() {
492
+ * let fragSrc = `precision highp float;
493
+ * void main() {
494
+ * gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);
495
+ * }`;
496
+ *
497
+ * createCanvas(100, 100, WEBGL);
498
+ * let s = createFilterShader(fragSrc);
499
+ * filter(s);
500
+ * describe('a yellow canvas');
501
+ * }
502
+ * </code>
503
+ * </div>
504
+ *
505
+ * <div modernizr='webgl'>
506
+ * <code>
507
+ * let img, s;
508
+ * async function setup() {
509
+ * img = await loadImage('assets/bricks.jpg');
510
+ * let fragSrc = `precision highp float;
511
+ *
512
+ * // x,y coordinates, given from the vertex shader
513
+ * varying vec2 vTexCoord;
514
+ *
515
+ * // the canvas contents, given from filter()
516
+ * uniform sampler2D tex0;
517
+ * // other useful information from the canvas
518
+ * uniform vec2 texelSize;
519
+ * uniform vec2 canvasSize;
520
+ * // a custom variable from this sketch
521
+ * uniform float darkness;
522
+ *
523
+ * void main() {
524
+ * // get the color at current pixel
525
+ * vec4 color = texture2D(tex0, vTexCoord);
526
+ * // set the output color
527
+ * color.b = 1.0;
528
+ * color *= darkness;
529
+ * gl_FragColor = vec4(color.rgb, 1.0);
530
+ * }`;
531
+ *
532
+ * createCanvas(100, 100, WEBGL);
533
+ * s = createFilterShader(fragSrc);
534
+ * }
535
+ *
536
+ * function draw() {
537
+ * image(img, -50, -50);
538
+ * s.setUniform('darkness', 0.5);
539
+ * filter(s);
540
+ * describe('a image of bricks tinted dark blue');
541
+ * }
542
+ * </code>
543
+ * </div>
544
+ */
545
+ function createFilterShader(fragSrc: string): p5.Shader;
546
+
547
+ /**
548
+ * Sets the p5.Shader object to apply while drawing.Shaders are programs that run on the graphics processing unit (GPU). They
549
+ * can process many pixels or vertices at the same time, making them fast for
550
+ * many graphics tasks. They’re written in a language called
551
+ * GLSL
552
+ * and run along with the rest of the code in a sketch.
553
+ * p5.Shader objects can be created using the
554
+ * createShader() and
555
+ * loadShader() functions.The parameter, `s`, is the p5.Shader object to
556
+ * apply. For example, calling `shader(myShader)` applies `myShader` to
557
+ * process each pixel on the canvas. This only changes the fill (the inner part of shapes),
558
+ * but does not affect the outlines (strokes) or any images drawn using the `image()` function.
559
+ * The source code from a p5.Shader object's
560
+ * fragment and vertex shaders will be compiled the first time it's passed to
561
+ * `shader()`. See
562
+ * MDN
563
+ * for more information about compiling shaders.Calling resetShader() restores a sketch’s
564
+ * default shaders.Note: Shaders can only be used in WebGL mode.If you want to apply shaders to strokes or images, use the following methods:
565
+ *
566
+ * @param <a href="#/p5.Shader">p5.Shader</a> object
567
+ * to apply.
568
+ * @example <div modernizr='webgl'>
569
+ * <code>
570
+ * let fillShader;
571
+ *
572
+ * let vertSrc = `
573
+ * precision highp float;
574
+ * attribute vec3 aPosition;
575
+ * uniform mat4 uModelViewMatrix;
576
+ * uniform mat4 uProjectionMatrix;
577
+ * varying vec3 vPosition;
578
+ *
579
+ * void main() {
580
+ * vPosition = aPosition;
581
+ * gl_Position = uProjectionMatrix * uModelViewMatrix * vec4(aPosition, 1.0);
582
+ * }
583
+ * `;
584
+ *
585
+ * let fragSrc = `
586
+ * precision highp float;
587
+ * uniform vec3 uLightDir;
588
+ * varying vec3 vPosition;
589
+ *
590
+ * void main() {
591
+ * vec3 lightDir = normalize(uLightDir);
592
+ * float brightness = dot(lightDir, normalize(vPosition));
593
+ * brightness = clamp(brightness, 0.4, 1.0);
594
+ * vec3 color = vec3(0.3, 0.5, 1.0);
595
+ * color = color * brightness * 3.0;
596
+ * gl_FragColor = vec4(color, 1.0);
597
+ * }
598
+ * `;
599
+ *
600
+ * function setup() {
601
+ * createCanvas(200, 200, WEBGL);
602
+ * fillShader = createShader(vertSrc, fragSrc);
603
+ * noStroke();
604
+ * describe('A rotating torus with simulated directional lighting.');
605
+ * }
606
+ *
607
+ * function draw() {
608
+ * background(20, 20, 40);
609
+ * let lightDir = [0.5, 0.5, -1.0];
610
+ * fillShader.setUniform('uLightDir', lightDir);
611
+ * shader(fillShader);
612
+ * rotateY(frameCount * 0.02);
613
+ * rotateX(frameCount * 0.02);
614
+ * //lights();
615
+ * torus(25, 10, 30, 30);
616
+ * }
617
+ * </code>
618
+ * </div>
619
+ * @example <div modernizr='webgl'>
620
+ * <code>
621
+ * let fillShader;
622
+ *
623
+ * let vertSrc = `
624
+ * precision highp float;
625
+ * attribute vec3 aPosition;
626
+ * uniform mat4 uProjectionMatrix;
627
+ * uniform mat4 uModelViewMatrix;
628
+ * varying vec3 vPosition;
629
+ * void main() {
630
+ * vPosition = aPosition;
631
+ * gl_Position = uProjectionMatrix * uModelViewMatrix * vec4(aPosition, 1.0);
632
+ * }
633
+ * `;
634
+ *
635
+ * let fragSrc = `
636
+ * precision highp float;
637
+ * uniform vec3 uLightPos;
638
+ * uniform vec3 uFillColor;
639
+ * varying vec3 vPosition;
640
+ * void main() {
641
+ * float brightness = dot(normalize(uLightPos), normalize(vPosition));
642
+ * brightness = clamp(brightness, 0.0, 1.0);
643
+ * vec3 color = uFillColor * brightness;
644
+ * gl_FragColor = vec4(color, 1.0);
645
+ * }
646
+ * `;
647
+ *
648
+ * function setup() {
649
+ * createCanvas(200, 200, WEBGL);
650
+ * fillShader = createShader(vertSrc, fragSrc);
651
+ * shader(fillShader);
652
+ * noStroke();
653
+ * describe('A square affected by both fill color and lighting, with lights controlled by mouse.');
654
+ * }
655
+ *
656
+ * function draw() {
657
+ * let lightPos = [(mouseX - width / 2) / width,
658
+ * (mouseY - height / 2) / height, 1.0];
659
+ * fillShader.setUniform('uLightPos', lightPos);
660
+ * let fillColor = [map(mouseX, 0, width, 0, 1),
661
+ * map(mouseY, 0, height, 0, 1), 0.5];
662
+ * fillShader.setUniform('uFillColor', fillColor);
663
+ * plane(100, 100);
664
+ * }
665
+ * </code>
666
+ * </div>
667
+ * @example <div modernizr='webgl'>
668
+ * <code>
669
+ * let myShader;
670
+ *
671
+ * function setup() {
672
+ * createCanvas(200, 200, WEBGL);
673
+ *
674
+ * myShader = baseMaterialShader().modify({
675
+ * declarations: 'uniform float time;',
676
+ * 'vec4 getFinalColor': `(vec4 color) {
677
+ * float r = 0.2 + 0.5 * abs(sin(time + 0.0));
678
+ * float g = 0.2 + 0.5 * abs(sin(time + 1.0));
679
+ * float b = 0.2 + 0.5 * abs(sin(time + 2.0));
680
+ * color.rgb = vec3(r, g, b);
681
+ * return color;
682
+ * }`
683
+ * });
684
+ *
685
+ * noStroke();
686
+ * describe('A 3D cube with dynamically changing colors on a beige background.');
687
+ * }
688
+ *
689
+ * function draw() {
690
+ * background(245, 245, 220);
691
+ * shader(myShader);
692
+ * myShader.setUniform('time', millis() / 1000.0);
693
+ *
694
+ * box(50);
695
+ * }
696
+ * </code>
697
+ * </div>
698
+ */
699
+ function shader(s: p5.Shader): void;
700
+
701
+ /**
702
+ * Sets the p5.Shader object to apply for strokes.This method applies the given shader to strokes, allowing customization of
703
+ * how lines and outlines are drawn in 3D space. The shader will be used for
704
+ * strokes until resetShader() is called or another
705
+ * strokeShader is applied.The shader will be used for:To further customize its behavior, refer to the various hooks provided by
706
+ * the baseStrokeShader() method, which allow
707
+ * control over stroke weight, vertex positions, colors, and more.
708
+ *
709
+ * @param <a href="#/p5.Shader">p5.Shader</a> object
710
+ * to apply for strokes.
711
+ * @example <div modernizr='webgl'>
712
+ * <code>
713
+ * let animatedStrokeShader;
714
+ *
715
+ * let vertSrc = `
716
+ * precision mediump int;
717
+ *
718
+ * uniform mat4 uModelViewMatrix;
719
+ * uniform mat4 uProjectionMatrix;
720
+ * uniform float uStrokeWeight;
721
+ *
722
+ * uniform bool uUseLineColor;
723
+ * uniform vec4 uMaterialColor;
724
+ *
725
+ * uniform vec4 uViewport;
726
+ * uniform int uPerspective;
727
+ * uniform int uStrokeJoin;
728
+ *
729
+ * attribute vec4 aPosition;
730
+ * attribute vec3 aTangentIn;
731
+ * attribute vec3 aTangentOut;
732
+ * attribute float aSide;
733
+ * attribute vec4 aVertexColor;
734
+ *
735
+ * void main() {
736
+ * vec4 posp = uModelViewMatrix * aPosition;
737
+ * vec4 posqIn = uModelViewMatrix * (aPosition + vec4(aTangentIn, 0));
738
+ * vec4 posqOut = uModelViewMatrix * (aPosition + vec4(aTangentOut, 0));
739
+ *
740
+ * float facingCamera = pow(
741
+ * abs(normalize(posqIn-posp).z),
742
+ * 0.25
743
+ * );
744
+ *
745
+ * float scale = mix(1., 0.995, facingCamera);
746
+ *
747
+ * posp.xyz = posp.xyz * scale;
748
+ * posqIn.xyz = posqIn.xyz * scale;
749
+ * posqOut.xyz = posqOut.xyz * scale;
750
+ *
751
+ * vec4 p = uProjectionMatrix * posp;
752
+ * vec4 qIn = uProjectionMatrix * posqIn;
753
+ * vec4 qOut = uProjectionMatrix * posqOut;
754
+ *
755
+ * vec2 tangentIn = normalize((qIn.xy*p.w - p.xy*qIn.w) * uViewport.zw);
756
+ * vec2 tangentOut = normalize((qOut.xy*p.w - p.xy*qOut.w) * uViewport.zw);
757
+ *
758
+ * vec2 curPerspScale;
759
+ * if(uPerspective == 1) {
760
+ * curPerspScale = (uProjectionMatrix * vec4(1, sign(uProjectionMatrix[1][1]), 0, 0)).xy;
761
+ * } else {
762
+ * curPerspScale = p.w / (0.5 * uViewport.zw);
763
+ * }
764
+ *
765
+ * vec2 offset;
766
+ * vec2 tangent = aTangentIn == vec3(0.) ? tangentOut : tangentIn;
767
+ * vec2 normal = vec2(-tangent.y, tangent.x);
768
+ * float normalOffset = sign(aSide);
769
+ * float tangentOffset = abs(aSide) - 1.;
770
+ * offset = (normal * normalOffset + tangent * tangentOffset) *
771
+ * uStrokeWeight * 0.5;
772
+ *
773
+ * gl_Position.xy = p.xy + offset.xy * curPerspScale;
774
+ * gl_Position.zw = p.zw;
775
+ * }
776
+ * `;
777
+ *
778
+ * let fragSrc = `
779
+ * precision mediump float;
780
+ * uniform float uTime;
781
+ *
782
+ * void main() {
783
+ * float wave = sin(gl_FragCoord.x * 0.1 + uTime) * 0.5 + 0.5;
784
+ * gl_FragColor = vec4(wave, 0.5, 1.0, 1.0); // Animated color based on time
785
+ * }
786
+ * `;
787
+ *
788
+ * function setup() {
789
+ * createCanvas(200, 200, WEBGL);
790
+ * animatedStrokeShader = createShader(vertSrc, fragSrc);
791
+ * strokeShader(animatedStrokeShader);
792
+ * strokeWeight(4);
793
+ *
794
+ * describe('A hollow cube rotating continuously with its stroke colors changing dynamically over time against a static gray background.');
795
+ * }
796
+ *
797
+ * function draw() {
798
+ * animatedStrokeShader.setUniform('uTime', millis() / 1000.0);
799
+ * background(250);
800
+ * rotateY(frameCount * 0.02);
801
+ * noFill();
802
+ * orbitControl();
803
+ * box(50);
804
+ * }
805
+ * </code>
806
+ * </div>
807
+ * @example <div modernizr='webgl'>
808
+ * <code>
809
+ * let myShader;
810
+ *
811
+ * function setup() {
812
+ * createCanvas(200, 200, WEBGL);
813
+ * myShader = baseStrokeShader().modify({
814
+ * 'float random': `(vec2 p) {
815
+ * vec3 p3 = fract(vec3(p.xyx) * .1471);
816
+ * p3 += dot(p3, p3.yzx + 32.33);
817
+ * return fract((p3.x + p3.y) * p3.z);
818
+ * }`,
819
+ * 'Inputs getPixelInputs': `(Inputs inputs) {
820
+ * // Modify alpha with dithering effect
821
+ * float a = inputs.color.a;
822
+ * inputs.color.a = 1.0;
823
+ * inputs.color *= random(inputs.position.xy) > a ? 0.0 : 1.0;
824
+ * return inputs;
825
+ * }`
826
+ * });
827
+ * }
828
+ *
829
+ * function draw() {
830
+ * background(255);
831
+ * strokeShader(myShader);
832
+ * strokeWeight(12);
833
+ * beginShape();
834
+ * for (let i = 0; i <= 50; i++) {
835
+ * stroke(
836
+ * map(i, 0, 50, 150, 255),
837
+ * 100 + 155 * sin(i / 5),
838
+ * 255 * map(i, 0, 50, 1, 0)
839
+ * );
840
+ * vertex(
841
+ * map(i, 0, 50, 1, -1) * width / 3,
842
+ * 50 * cos(i / 10 + frameCount / 80)
843
+ * );
844
+ * }
845
+ * endShape();
846
+ * }
847
+ * </code>
848
+ * </div>
849
+ */
850
+ function strokeShader(s: p5.Shader): void;
851
+
852
+ /**
853
+ * Sets the p5.Shader object to apply for images.This method allows the user to apply a custom shader to images, enabling
854
+ * advanced visual effects such as pixel manipulation, color adjustments,
855
+ * or dynamic behavior. The shader will be applied to the image drawn using
856
+ * the image() function.The shader will be used exclusively for:
857
+ *
858
+ * @param <a href="#/p5.Shader">p5.Shader</a> object
859
+ * to apply for images.
860
+ * @example <div modernizr='webgl'>
861
+ * <code>
862
+ * let img;
863
+ * let imgShader;
864
+ *
865
+ * async function setup() {
866
+ * img = await loadImage('assets/outdoor_image.jpg');
867
+ *
868
+ * createCanvas(200, 200, WEBGL);
869
+ * noStroke();
870
+ *
871
+ * imgShader = createShader(`
872
+ * precision mediump float;
873
+ * attribute vec3 aPosition;
874
+ * attribute vec2 aTexCoord;
875
+ * varying vec2 vTexCoord;
876
+ * uniform mat4 uModelViewMatrix;
877
+ * uniform mat4 uProjectionMatrix;
878
+ *
879
+ * void main() {
880
+ * vTexCoord = aTexCoord;
881
+ * gl_Position = uProjectionMatrix * uModelViewMatrix * vec4(aPosition, 1.0);
882
+ * }
883
+ * `, `
884
+ * precision mediump float;
885
+ * varying vec2 vTexCoord;
886
+ * uniform sampler2D uTexture;
887
+ * uniform vec2 uMousePos;
888
+ *
889
+ * void main() {
890
+ * vec4 texColor = texture2D(uTexture, vTexCoord);
891
+ * // Adjust the color based on mouse position
892
+ * float r = uMousePos.x * texColor.r;
893
+ * float g = uMousePos.y * texColor.g;
894
+ * gl_FragColor = vec4(r, g, texColor.b, texColor.a);
895
+ * }
896
+ * `);
897
+ *
898
+ * describe(
899
+ * 'An image on a gray background where the colors change based on the mouse position.'
900
+ * );
901
+ * }
902
+ *
903
+ * function draw() {
904
+ * background(220);
905
+ *
906
+ * imageShader(imgShader);
907
+ *
908
+ * // Map the mouse position to a range between 0 and 1
909
+ * let mousePosX = map(mouseX, 0, width, 0, 1);
910
+ * let mousePosY = map(mouseY, 0, height, 0, 1);
911
+ *
912
+ * // Pass the mouse position to the shader as a uniform
913
+ * imgShader.setUniform('uMousePos', [mousePosX, mousePosY]);
914
+ *
915
+ * // Bind the image texture to the shader
916
+ * imgShader.setUniform('uTexture', img);
917
+ *
918
+ * image(img, -width / 2, -height / 2, width, height);
919
+ * }
920
+ *
921
+ * </code>
922
+ * </div>
923
+ * @example <div modernizr='webgl'>
924
+ * <code>
925
+ * let img;
926
+ * let imgShader;
927
+ *
928
+ * async function setup() {
929
+ * img = await loadImage('assets/outdoor_image.jpg');
930
+ *
931
+ * createCanvas(200, 200, WEBGL);
932
+ * noStroke();
933
+ *
934
+ * imgShader = createShader(`
935
+ * precision mediump float;
936
+ * attribute vec3 aPosition;
937
+ * attribute vec2 aTexCoord;
938
+ * varying vec2 vTexCoord;
939
+ * uniform mat4 uModelViewMatrix;
940
+ * uniform mat4 uProjectionMatrix;
941
+ *
942
+ * void main() {
943
+ * vTexCoord = aTexCoord;
944
+ * gl_Position = uProjectionMatrix * uModelViewMatrix * vec4(aPosition, 1.0);
945
+ * }
946
+ * `, `
947
+ * precision mediump float;
948
+ * varying vec2 vTexCoord;
949
+ * uniform sampler2D uTexture;
950
+ * uniform vec2 uMousePos;
951
+ *
952
+ * void main() {
953
+ * // Distance from the current pixel to the mouse
954
+ * float distFromMouse = distance(vTexCoord, uMousePos);
955
+ *
956
+ * // Adjust pixelation based on distance (closer = more detail, farther = blockier)
957
+ * float pixelSize = mix(0.002, 0.05, distFromMouse);
958
+ * vec2 pixelatedCoord = vec2(floor(vTexCoord.x / pixelSize) * pixelSize,
959
+ * floor(vTexCoord.y / pixelSize) * pixelSize);
960
+ *
961
+ * vec4 texColor = texture2D(uTexture, pixelatedCoord);
962
+ * gl_FragColor = texColor;
963
+ * }
964
+ * `);
965
+ *
966
+ * describe('A static image with a grid-like, pixelated effect created by the shader. Each cell in the grid alternates visibility, producing a dithered visual effect.');
967
+ * }
968
+ *
969
+ * function draw() {
970
+ * background(220);
971
+ * imageShader(imgShader);
972
+ *
973
+ * let mousePosX = map(mouseX, 0, width, 0, 1);
974
+ * let mousePosY = map(mouseY, 0, height, 0, 1);
975
+ *
976
+ * imgShader.setUniform('uMousePos', [mousePosX, mousePosY]);
977
+ * imgShader.setUniform('uTexture', img);
978
+ * image(img, -width / 2, -height / 2, width, height);
979
+ * }
980
+ * </code>
981
+ * </div>
982
+ */
983
+ function imageShader(s: p5.Shader): void;
984
+
985
+ /**
986
+ * Get the default shader used with lights, materials,
987
+ * and textures.You can call `baseMaterialShader().modify()`
988
+ * and change any of the following hooks:`void beforeVertex`Called at the start of the vertex shader.`Vertex getObjectInputs`Update the vertex data of the model being drawn before any positioning has been applied. It takes in a `Vertex` struct, which includes:`Vertex getWorldInputs`Update the vertex data of the model being drawn after transformations such as `translate()` and `scale()` have been applied, but before the camera has been applied. It takes in a `Vertex` struct like, in the `getObjectInputs` hook above, that can be modified and returned.`Vertex getCameraInputs`Update the vertex data of the model being drawn as they appear relative to the camera. It takes in a `Vertex` struct like, in the `getObjectInputs` hook above, that can be modified and returned.`void afterVertex`Called at the end of the vertex shader.`void beforeFragment`Called at the start of the fragment shader.`Inputs getPixelInputs`Update the per-pixel inputs of the material. It takes in an `Inputs` struct, which includes:`vec4 combineColors`Take in a `ColorComponents` struct containing all the different components of light, and combining them into
989
+ * a single final color. The struct contains:`vec4 getFinalColor`Update the final color after mixing. It takes in a `vec4 color` and must return a modified version.`void afterFragment`Called at the end of the fragment shader.Most of the time, you will need to write your hooks in GLSL ES version 300. If you
990
+ * are using WebGL 1 instead of 2, write your hooks in GLSL ES 100 instead.Call `baseMaterialShader().inspectHooks()` to see all the possible hooks and
991
+ * their default implementations.
992
+ *
993
+ * @returns The material shader
994
+ * @example <div modernizr='webgl'>
995
+ * <code>
996
+ * let myShader;
997
+ *
998
+ * function setup() {
999
+ * createCanvas(200, 200, WEBGL);
1000
+ * myShader = baseMaterialShader().modify(() => {
1001
+ * let time = uniformFloat(() => millis());
1002
+ * getWorldInputs((inputs) => {
1003
+ * inputs.position.y +=
1004
+ * 20 * sin(time * 0.001 + inputs.position.x * 0.05);
1005
+ * return inputs;
1006
+ * });
1007
+ * });
1008
+ * }
1009
+ *
1010
+ * function draw() {
1011
+ * background(255);
1012
+ * shader(myShader);
1013
+ * lights();
1014
+ * noStroke();
1015
+ * fill('red');
1016
+ * sphere(50);
1017
+ * }
1018
+ * </code>
1019
+ * </div>
1020
+ * @example <div modernizr='webgl'>
1021
+ * <code>
1022
+ * let myShader;
1023
+ *
1024
+ * function setup() {
1025
+ * createCanvas(200, 200, WEBGL);
1026
+ * myShader = baseMaterialShader().modify({
1027
+ * declarations: 'vec3 myNormal;',
1028
+ * 'Inputs getPixelInputs': `(Inputs inputs) {
1029
+ * myNormal = inputs.normal;
1030
+ * return inputs;
1031
+ * }`,
1032
+ * 'vec4 getFinalColor': `(vec4 color) {
1033
+ * return mix(
1034
+ * vec4(1.0, 1.0, 1.0, 1.0),
1035
+ * color,
1036
+ * abs(dot(myNormal, vec3(0.0, 0.0, 1.0)))
1037
+ * );
1038
+ * }`
1039
+ * });
1040
+ * }
1041
+ *
1042
+ * function draw() {
1043
+ * background(255);
1044
+ * rotateY(millis() * 0.001);
1045
+ * shader(myShader);
1046
+ * lights();
1047
+ * noStroke();
1048
+ * fill('red');
1049
+ * torus(30);
1050
+ * }
1051
+ * </code>
1052
+ * </div>
1053
+ * @example <div modernizr='webgl'>
1054
+ * <code>
1055
+ * let myShader;
1056
+ * let environment;
1057
+ *
1058
+ * async function setup() {
1059
+ * environment = await loadImage('assets/outdoor_spheremap.jpg');
1060
+ *
1061
+ * createCanvas(200, 200, WEBGL);
1062
+ * myShader = baseMaterialShader().modify(() => {
1063
+ * getPixelInputs((inputs) => {
1064
+ * let factor = sin(
1065
+ * TWO_PI * (inputs.texCoord.x + inputs.texCoord.y)
1066
+ * );
1067
+ * inputs.shininess = mix(1, 100, factor);
1068
+ * inputs.metalness = factor;
1069
+ * return inputs;
1070
+ * })
1071
+ * });
1072
+ * }
1073
+ *
1074
+ * function draw() {
1075
+ * panorama(environment);
1076
+ * ambientLight(100);
1077
+ * imageLight(environment);
1078
+ * rotateY(millis() * 0.001);
1079
+ * shader(myShader);
1080
+ * noStroke();
1081
+ * fill(255);
1082
+ * specularMaterial(150);
1083
+ * sphere(50);
1084
+ * }
1085
+ * </code>
1086
+ * </div>
1087
+ * @example <div modernizr='webgl'>
1088
+ * <code>
1089
+ * let myShader;
1090
+ *
1091
+ * function setup() {
1092
+ * createCanvas(200, 200, WEBGL);
1093
+ * myShader = baseMaterialShader().modify(() => {
1094
+ * getPixelInputs((inputs) => {
1095
+ * inputs.normal.x += 0.2 * sin(
1096
+ * sin(TWO_PI * dot(inputs.texCoord.yx, vec2(10, 25)))
1097
+ * );
1098
+ * inputs.normal.y += 0.2 * sin(
1099
+ * sin(TWO_PI * dot(inputs.texCoord, vec2(10, 25)))
1100
+ * );
1101
+ * inputs.normal = normalize(inputs.normal);
1102
+ * return inputs;
1103
+ * });
1104
+ * });
1105
+ * }
1106
+ *
1107
+ * function draw() {
1108
+ * background(255);
1109
+ * shader(myShader);
1110
+ * ambientLight(150);
1111
+ * pointLight(
1112
+ * 255, 255, 255,
1113
+ * 100*cos(frameCount*0.04), -50, 100*sin(frameCount*0.04)
1114
+ * );
1115
+ * noStroke();
1116
+ * fill('red');
1117
+ * shininess(200);
1118
+ * specularMaterial(255);
1119
+ * sphere(50);
1120
+ * }
1121
+ * </code>
1122
+ * </div>
1123
+ */
1124
+ function baseMaterialShader(): p5.Shader;
1125
+
1126
+ /**
1127
+ * Get the base shader for filters.You can then call `baseFilterShader().modify()`
1128
+ * and change the following hook:`vec4 getColor`Output the final color for the current pixel. It takes in two parameters:
1129
+ * `FilterInputs inputs`, and `in sampler2D canvasContent`, and must return a color
1130
+ * as a `vec4`.`FilterInputs inputs` is a scruct with the following properties:`in sampler2D canvasContent` is a texture with the contents of the sketch, pre-filter. Call
1131
+ * `getTexture(canvasContent, someCoordinate)` to retrieve the color of the sketch at that coordinate,
1132
+ * with coordinate values between 0 and 1.Most of the time, you will need to write your hooks in GLSL ES version 300. If you
1133
+ * are using WebGL 1, write your hooks in GLSL ES 100 instead.
1134
+ *
1135
+ * @returns The filter shader
1136
+ * @example <div modernizr='webgl'>
1137
+ * <code>
1138
+ * let img;
1139
+ * let myShader;
1140
+ *
1141
+ * async function setup() {
1142
+ * img = await loadImage('assets/bricks.jpg');
1143
+ * createCanvas(100, 100, WEBGL);
1144
+ * myShader = baseFilterShader().modify(() => {
1145
+ * let time = uniformFloat(() => millis());
1146
+ * getColor((inputs, canvasContent) => {
1147
+ * inputs.texCoord.y +=
1148
+ * 0.02 * sin(time * 0.001 + inputs.texCoord.x * 5);
1149
+ * return texture(canvasContent, inputs.texCoord);
1150
+ * });
1151
+ * });
1152
+ * }
1153
+ *
1154
+ * function draw() {
1155
+ * image(img, -50, -50);
1156
+ * filter(myShader);
1157
+ * describe('an image of bricks, distorting over time');
1158
+ * }
1159
+ * </code>
1160
+ * </div>
1161
+ */
1162
+ function baseFilterShader(): p5.Shader;
1163
+
1164
+ /**
1165
+ * Get the shader used by `normalMaterial()`.You can call `baseNormalShader().modify()`
1166
+ * and change any of the following hooks:`void beforeVertex`Called at the start of the vertex shader.`Vertex getObjectInputs`Update the vertex data of the model being drawn before any positioning has been applied. It takes in a `Vertex` struct, which includes:`Vertex getWorldInputs`Update the vertex data of the model being drawn after transformations such as `translate()` and `scale()` have been applied, but before the camera has been applied. It takes in a `Vertex` struct like, in the `getObjectInputs` hook above, that can be modified and returned.`Vertex getCameraInputs`Update the vertex data of the model being drawn as they appear relative to the camera. It takes in a `Vertex` struct like, in the `getObjectInputs` hook above, that can be modified and returned.`void afterVertex`Called at the end of the vertex shader.`void beforeFragment`Called at the start of the fragment shader.`vec4 getFinalColor`Update the final color after mixing. It takes in a `vec4 color` and must return a modified version.`void afterFragment`Called at the end of the fragment shader.Most of the time, you will need to write your hooks in GLSL ES version 300. If you
1167
+ * are using WebGL 1 instead of 2, write your hooks in GLSL ES 100 instead.Call `baseNormalShader().inspectHooks()` to see all the possible hooks and
1168
+ * their default implementations.
1169
+ *
1170
+ * @returns The `normalMaterial` shader
1171
+ * @example <div modernizr='webgl'>
1172
+ * <code>
1173
+ * let myShader;
1174
+ *
1175
+ * function setup() {
1176
+ * createCanvas(200, 200, WEBGL);
1177
+ * myShader = baseNormalShader().modify({
1178
+ * uniforms: {
1179
+ * 'float time': () => millis()
1180
+ * },
1181
+ * 'Vertex getWorldInputs': `(Vertex inputs) {
1182
+ * inputs.position.y +=
1183
+ * 20. * sin(time * 0.001 + inputs.position.x * 0.05);
1184
+ * return inputs;
1185
+ * }`
1186
+ * });
1187
+ * }
1188
+ *
1189
+ * function draw() {
1190
+ * background(255);
1191
+ * shader(myShader);
1192
+ * noStroke();
1193
+ * sphere(50);
1194
+ * }
1195
+ * </code>
1196
+ * </div>
1197
+ * @example <div modernizr='webgl'>
1198
+ * <code>
1199
+ * let myShader;
1200
+ *
1201
+ * function setup() {
1202
+ * createCanvas(200, 200, WEBGL);
1203
+ * myShader = baseNormalShader().modify({
1204
+ * 'Vertex getCameraInputs': `(Vertex inputs) {
1205
+ * inputs.normal = abs(inputs.normal);
1206
+ * return inputs;
1207
+ * }`,
1208
+ * 'vec4 getFinalColor': `(vec4 color) {
1209
+ * // Map the r, g, and b values of the old normal to new colors
1210
+ * // instead of just red, green, and blue:
1211
+ * vec3 newColor =
1212
+ * color.r * vec3(89.0, 240.0, 232.0) / 255.0 +
1213
+ * color.g * vec3(240.0, 237.0, 89.0) / 255.0 +
1214
+ * color.b * vec3(205.0, 55.0, 222.0) / 255.0;
1215
+ * newColor = newColor / (color.r + color.g + color.b);
1216
+ * return vec4(newColor, 1.0) * color.a;
1217
+ * }`
1218
+ * });
1219
+ * }
1220
+ *
1221
+ * function draw() {
1222
+ * background(255);
1223
+ * shader(myShader);
1224
+ * noStroke();
1225
+ * rotateX(frameCount * 0.01);
1226
+ * rotateY(frameCount * 0.015);
1227
+ * box(100);
1228
+ * }
1229
+ * </code>
1230
+ * </div>
1231
+ */
1232
+ function baseNormalShader(): p5.Shader;
1233
+
1234
+ /**
1235
+ * Get the shader used when no lights or materials are applied.You can call `baseColorShader().modify()`
1236
+ * and change any of the following hooks:`void beforeVertex`Called at the start of the vertex shader.`Vertex getObjectInputs`Update the vertex data of the model being drawn before any positioning has been applied. It takes in a `Vertex` struct, which includes:`Vertex getWorldInputs`Update the vertex data of the model being drawn after transformations such as `translate()` and `scale()` have been applied, but before the camera has been applied. It takes in a `Vertex` struct like, in the `getObjectInputs` hook above, that can be modified and returned.`Vertex getCameraInputs`Update the vertex data of the model being drawn as they appear relative to the camera. It takes in a `Vertex` struct like, in the `getObjectInputs` hook above, that can be modified and returned.`void afterVertex`Called at the end of the vertex shader.`void beforeFragment`Called at the start of the fragment shader.`vec4 getFinalColor`Update the final color after mixing. It takes in a `vec4 color` and must return a modified version.`void afterFragment`Called at the end of the fragment shader.Most of the time, you will need to write your hooks in GLSL ES version 300. If you
1237
+ * are using WebGL 1 instead of 2, write your hooks in GLSL ES 100 instead.Call `baseColorShader().inspectHooks()` to see all the possible hooks and
1238
+ * their default implementations.
1239
+ *
1240
+ * @returns The color shader
1241
+ * @example <div modernizr='webgl'>
1242
+ * <code>
1243
+ * let myShader;
1244
+ *
1245
+ * function setup() {
1246
+ * createCanvas(200, 200, WEBGL);
1247
+ * myShader = baseColorShader().modify({
1248
+ * uniforms: {
1249
+ * 'float time': () => millis()
1250
+ * },
1251
+ * 'Vertex getWorldInputs': `(Vertex inputs) {
1252
+ * inputs.position.y +=
1253
+ * 20. * sin(time * 0.001 + inputs.position.x * 0.05);
1254
+ * return inputs;
1255
+ * }`
1256
+ * });
1257
+ * }
1258
+ *
1259
+ * function draw() {
1260
+ * background(255);
1261
+ * shader(myShader);
1262
+ * noStroke();
1263
+ * fill('red');
1264
+ * circle(0, 0, 50);
1265
+ * }
1266
+ * </code>
1267
+ * </div>
1268
+ */
1269
+ function baseColorShader(): p5.Shader;
1270
+
1271
+ /**
1272
+ * Get the shader used when drawing the strokes of shapes.You can call `baseStrokeShader().modify()`
1273
+ * and change any of the following hooks:`void beforeVertex`Called at the start of the vertex shader.`StrokeVertex getObjectInputs`Update the vertex data of the stroke being drawn before any positioning has been applied. It takes in a `StrokeVertex` struct, which includes:`StrokeVertex getWorldInputs`Update the vertex data of the model being drawn after transformations such as `translate()` and `scale()` have been applied, but before the camera has been applied. It takes in a `StrokeVertex` struct like, in the `getObjectInputs` hook above, that can be modified and returned.`StrokeVertex getCameraInputs`Update the vertex data of the model being drawn as they appear relative to the camera. It takes in a `StrokeVertex` struct like, in the `getObjectInputs` hook above, that can be modified and returned.`void afterVertex`Called at the end of the vertex shader.`void beforeFragment`Called at the start of the fragment shader.`Inputs getPixelInputs`Update the inputs to the shader. It takes in a struct `Inputs inputs`, which includes:`bool shouldDiscard`Caps and joins are made by discarded pixels in the fragment shader to carve away unwanted areas. Use this to change this logic. It takes in a `bool willDiscard` and must return a modified version.`vec4 getFinalColor`Update the final color after mixing. It takes in a `vec4 color` and must return a modified version.`void afterFragment`Called at the end of the fragment shader.Most of the time, you will need to write your hooks in GLSL ES version 300. If you
1274
+ * are using WebGL 1 instead of 2, write your hooks in GLSL ES 100 instead.Call `baseStrokeShader().inspectHooks()` to see all the possible hooks and
1275
+ * their default implementations.
1276
+ *
1277
+ * @returns The stroke shader
1278
+ * @example <div modernizr='webgl'>
1279
+ * <code>
1280
+ * let myShader;
1281
+ *
1282
+ * function setup() {
1283
+ * createCanvas(200, 200, WEBGL);
1284
+ * myShader = baseStrokeShader().modify({
1285
+ * 'Inputs getPixelInputs': `(Inputs inputs) {
1286
+ * float opacity = 1.0 - smoothstep(
1287
+ * 0.0,
1288
+ * 15.0,
1289
+ * length(inputs.position - inputs.center)
1290
+ * );
1291
+ * inputs.color *= opacity;
1292
+ * return inputs;
1293
+ * }`
1294
+ * });
1295
+ * }
1296
+ *
1297
+ * function draw() {
1298
+ * background(255);
1299
+ * strokeShader(myShader);
1300
+ * strokeWeight(30);
1301
+ * line(
1302
+ * -width/3,
1303
+ * sin(millis()*0.001) * height/4,
1304
+ * width/3,
1305
+ * sin(millis()*0.001 + 1) * height/4
1306
+ * );
1307
+ * }
1308
+ * </code>
1309
+ * </div>
1310
+ * @example <div modernizr='webgl'>
1311
+ * <code>
1312
+ * let myShader;
1313
+ *
1314
+ * function setup() {
1315
+ * createCanvas(200, 200, WEBGL);
1316
+ * myShader = baseStrokeShader().modify({
1317
+ * uniforms: {
1318
+ * 'float time': () => millis()
1319
+ * },
1320
+ * 'StrokeVertex getWorldInputs': `(StrokeVertex inputs) {
1321
+ * // Add a somewhat random offset to the weight
1322
+ * // that varies based on position and time
1323
+ * float scale = 0.8 + 0.2*sin(10.0 * sin(
1324
+ * floor(time/250.) +
1325
+ * inputs.position.x*0.01 +
1326
+ * inputs.position.y*0.01
1327
+ * ));
1328
+ * inputs.weight *= scale;
1329
+ * return inputs;
1330
+ * }`
1331
+ * });
1332
+ * }
1333
+ *
1334
+ * function draw() {
1335
+ * background(255);
1336
+ * strokeShader(myShader);
1337
+ * myShader.setUniform('time', millis());
1338
+ * strokeWeight(10);
1339
+ * beginShape();
1340
+ * for (let i = 0; i <= 50; i++) {
1341
+ * let r = map(i, 0, 50, 0, width/3);
1342
+ * let x = r*cos(i*0.2);
1343
+ * let y = r*sin(i*0.2);
1344
+ * vertex(x, y);
1345
+ * }
1346
+ * endShape();
1347
+ * }
1348
+ * </code>
1349
+ * </div>
1350
+ * @example <div modernizr='webgl'>
1351
+ * <code>
1352
+ * let myShader;
1353
+ *
1354
+ * function setup() {
1355
+ * createCanvas(200, 200, WEBGL);
1356
+ * myShader = baseStrokeShader().modify({
1357
+ * 'float random': `(vec2 p) {
1358
+ * vec3 p3 = fract(vec3(p.xyx) * .1031);
1359
+ * p3 += dot(p3, p3.yzx + 33.33);
1360
+ * return fract((p3.x + p3.y) * p3.z);
1361
+ * }`,
1362
+ * 'Inputs getPixelInputs': `(Inputs inputs) {
1363
+ * // Replace alpha in the color with dithering by
1364
+ * // randomly setting pixel colors to 0 based on opacity
1365
+ * float a = inputs.color.a;
1366
+ * inputs.color.a = 1.0;
1367
+ * inputs.color *= random(inputs.position.xy) > a ? 0.0 : 1.0;
1368
+ * return inputs;
1369
+ * }`
1370
+ * });
1371
+ * }
1372
+ *
1373
+ * function draw() {
1374
+ * background(255);
1375
+ * strokeShader(myShader);
1376
+ * strokeWeight(10);
1377
+ * beginShape();
1378
+ * for (let i = 0; i <= 50; i++) {
1379
+ * stroke(
1380
+ * 0,
1381
+ * 255
1382
+ * * map(i, 0, 20, 0, 1, true)
1383
+ * * map(i, 30, 50, 1, 0, true)
1384
+ * );
1385
+ * vertex(
1386
+ * map(i, 0, 50, -1, 1) * width/3,
1387
+ * 50 * sin(i/10 + frameCount/100)
1388
+ * );
1389
+ * }
1390
+ * endShape();
1391
+ * }
1392
+ * </code>
1393
+ * </div>
1394
+ */
1395
+ function baseStrokeShader(): p5.Shader;
1396
+
1397
+ /**
1398
+ * Restores the default shaders.`resetShader()` deactivates any shaders previously applied by
1399
+ * shader(), strokeShader(),
1400
+ * or imageShader().Note: Shaders can only be used in WebGL mode.
1401
+ *
1402
+ * @example <div>
1403
+ * <code>
1404
+ * // Create a string with the vertex shader program.
1405
+ * // The vertex shader is called for each vertex.
1406
+ * let vertSrc = `
1407
+ * attribute vec3 aPosition;
1408
+ * attribute vec2 aTexCoord;
1409
+ * uniform mat4 uProjectionMatrix;
1410
+ * uniform mat4 uModelViewMatrix;
1411
+ * varying vec2 vTexCoord;
1412
+ *
1413
+ * void main() {
1414
+ * vTexCoord = aTexCoord;
1415
+ * vec4 position = vec4(aPosition, 1.0);
1416
+ * gl_Position = uProjectionMatrix * uModelViewMatrix * position;
1417
+ * }
1418
+ * `;
1419
+ *
1420
+ * // Create a string with the fragment shader program.
1421
+ * // The fragment shader is called for each pixel.
1422
+ * let fragSrc = `
1423
+ * precision mediump float;
1424
+ * varying vec2 vTexCoord;
1425
+ *
1426
+ * void main() {
1427
+ * vec2 uv = vTexCoord;
1428
+ * vec3 color = vec3(uv.x, uv.y, min(uv.x + uv.y, 1.0));
1429
+ * gl_FragColor = vec4(color, 1.0);
1430
+ * }
1431
+ * `;
1432
+ *
1433
+ * let myShader;
1434
+ *
1435
+ * function setup() {
1436
+ * createCanvas(100, 100, WEBGL);
1437
+ *
1438
+ * // Create a p5.Shader object.
1439
+ * myShader = createShader(vertSrc, fragSrc);
1440
+ *
1441
+ * describe(
1442
+ * 'Two rotating cubes on a gray background. The left one has a blue-purple gradient on each face. The right one is red.'
1443
+ * );
1444
+ * }
1445
+ *
1446
+ * function draw() {
1447
+ * background(200);
1448
+ *
1449
+ * // Draw a box using the p5.Shader.
1450
+ * // shader() sets the active shader to myShader.
1451
+ * shader(myShader);
1452
+ * push();
1453
+ * translate(-25, 0, 0);
1454
+ * rotateX(frameCount * 0.01);
1455
+ * rotateY(frameCount * 0.01);
1456
+ * box(width / 4);
1457
+ * pop();
1458
+ *
1459
+ * // Draw a box using the default fill shader.
1460
+ * // resetShader() restores the default fill shader.
1461
+ * resetShader();
1462
+ * fill(255, 0, 0);
1463
+ * push();
1464
+ * translate(25, 0, 0);
1465
+ * rotateX(frameCount * 0.01);
1466
+ * rotateY(frameCount * 0.01);
1467
+ * box(width / 4);
1468
+ * pop();
1469
+ * }
1470
+ * </code>
1471
+ * </div>
1472
+ */
1473
+ function resetShader(): void;
1474
+
1475
+ /**
1476
+ * Sets the texture that will be used on shapes.A texture is like a skin that wraps around a shape. `texture()` works with
1477
+ * built-in shapes, such as square() and
1478
+ * sphere(), and custom shapes created with
1479
+ * functions such as buildGeometry(). To
1480
+ * texture a geometry created with beginShape(),
1481
+ * uv coordinates must be passed to each
1482
+ * vertex() call.The parameter, `tex`, is the texture to apply. `texture()` can use a range
1483
+ * of sources including images, videos, and offscreen renderers such as
1484
+ * p5.Graphics and
1485
+ * p5.Framebuffer objects.To texture a geometry created with beginShape(),
1486
+ * you will need to specify uv coordinates in vertex().Note: `texture()` can only be used in WebGL mode.
1487
+ *
1488
+ * @param media to use as the texture.
1489
+ * @example <div>
1490
+ * <code>
1491
+ * let img;
1492
+ *
1493
+ * async function setup() {
1494
+ * // Load an image and create a p5.Image object.
1495
+ * img = await loadImage('assets/laDefense.jpg');
1496
+ *
1497
+ * createCanvas(100, 100, WEBGL);
1498
+ *
1499
+ * describe('A spinning cube with an image of a ceiling on each face.');
1500
+ * }
1501
+ *
1502
+ * function draw() {
1503
+ * background(0);
1504
+ *
1505
+ * // Rotate around the x-, y-, and z-axes.
1506
+ * rotateZ(frameCount * 0.01);
1507
+ * rotateX(frameCount * 0.01);
1508
+ * rotateY(frameCount * 0.01);
1509
+ *
1510
+ * // Apply the image as a texture.
1511
+ * texture(img);
1512
+ *
1513
+ * // Draw the box.
1514
+ * box(50);
1515
+ * }
1516
+ * </code>
1517
+ * </div>
1518
+ *
1519
+ * <div>
1520
+ * <code>
1521
+ * let pg;
1522
+ *
1523
+ * function setup() {
1524
+ * createCanvas(100, 100, WEBGL);
1525
+ *
1526
+ * // Create a p5.Graphics object.
1527
+ * pg = createGraphics(100, 100);
1528
+ *
1529
+ * // Draw a circle to the p5.Graphics object.
1530
+ * pg.background(200);
1531
+ * pg.circle(50, 50, 30);
1532
+ *
1533
+ * describe('A spinning cube with circle at the center of each face.');
1534
+ * }
1535
+ *
1536
+ * function draw() {
1537
+ * background(0);
1538
+ *
1539
+ * // Rotate around the x-, y-, and z-axes.
1540
+ * rotateZ(frameCount * 0.01);
1541
+ * rotateX(frameCount * 0.01);
1542
+ * rotateY(frameCount * 0.01);
1543
+ *
1544
+ * // Apply the p5.Graphics object as a texture.
1545
+ * texture(pg);
1546
+ *
1547
+ * // Draw the box.
1548
+ * box(50);
1549
+ * }
1550
+ * </code>
1551
+ * </div>
1552
+ *
1553
+ * <div>
1554
+ * <code>
1555
+ * let vid;
1556
+ *
1557
+ * function setup() {
1558
+ * // Load a video and create a p5.MediaElement object.
1559
+ * vid = createVideo('assets/fingers.mov');
1560
+ *
1561
+ * createCanvas(100, 100, WEBGL);
1562
+ *
1563
+ * // Hide the video.
1564
+ * vid.hide();
1565
+ *
1566
+ * // Set the video to loop.
1567
+ * vid.loop();
1568
+ *
1569
+ * describe('A rectangle with video as texture');
1570
+ * }
1571
+ *
1572
+ * function draw() {
1573
+ * background(0);
1574
+ *
1575
+ * // Rotate around the y-axis.
1576
+ * rotateY(frameCount * 0.01);
1577
+ *
1578
+ * // Apply the video as a texture.
1579
+ * texture(vid);
1580
+ *
1581
+ * // Draw the rectangle.
1582
+ * rect(-40, -40, 80, 80);
1583
+ * }
1584
+ * </code>
1585
+ * </div>
1586
+ *
1587
+ * <div>
1588
+ * <code>
1589
+ * let vid;
1590
+ *
1591
+ * function setup() {
1592
+ * // Load a video and create a p5.MediaElement object.
1593
+ * vid = createVideo('assets/fingers.mov');
1594
+ *
1595
+ * createCanvas(100, 100, WEBGL);
1596
+ *
1597
+ * // Hide the video.
1598
+ * vid.hide();
1599
+ *
1600
+ * // Set the video to loop.
1601
+ * vid.loop();
1602
+ *
1603
+ * describe('A rectangle with video as texture');
1604
+ * }
1605
+ *
1606
+ * function draw() {
1607
+ * background(0);
1608
+ *
1609
+ * // Rotate around the y-axis.
1610
+ * rotateY(frameCount * 0.01);
1611
+ *
1612
+ * // Set the texture mode.
1613
+ * textureMode(NORMAL);
1614
+ *
1615
+ * // Apply the video as a texture.
1616
+ * texture(vid);
1617
+ *
1618
+ * // Draw a custom shape using uv coordinates.
1619
+ * beginShape();
1620
+ * vertex(-40, -40, 0, 0);
1621
+ * vertex(40, -40, 1, 0);
1622
+ * vertex(40, 40, 1, 1);
1623
+ * vertex(-40, 40, 0, 1);
1624
+ * endShape();
1625
+ * }
1626
+ * </code>
1627
+ * </div>
1628
+ */
1629
+ function texture(tex: p5.Image | p5.MediaElement | p5.Graphics | p5.Texture | p5.Framebuffer | p5.FramebufferTexture): void;
1630
+
1631
+ /**
1632
+ * Changes the coordinate system used for textures when they’re applied to
1633
+ * custom shapes.In order for texture() to work, a shape needs a
1634
+ * way to map the points on its surface to the pixels in an image. Built-in
1635
+ * shapes such as rect() and
1636
+ * box() already have these texture mappings based on
1637
+ * their vertices. Custom shapes created with
1638
+ * vertex() require texture mappings to be passed as
1639
+ * uv coordinates.Each call to vertex() must include 5 arguments,
1640
+ * as in `vertex(x, y, z, u, v)`, to map the vertex at coordinates `(x, y, z)`
1641
+ * to the pixel at coordinates `(u, v)` within an image. For example, the
1642
+ * corners of a rectangular image are mapped to the corners of a rectangle by default:// Draw the rectangle.
1643
+ * rect(0, 0, 30, 50);If the image in the code snippet above has dimensions of 300 x 500 pixels,
1644
+ * the same result could be achieved as follows:// Draw the rectangle.
1645
+ * beginShape();// Top-left.
1646
+ * // u: 0, v: 0
1647
+ * vertex(0, 0, 0, 0, 0);// Top-right.
1648
+ * // u: 300, v: 0
1649
+ * vertex(30, 0, 0, 300, 0);// Bottom-right.
1650
+ * // u: 300, v: 500
1651
+ * vertex(30, 50, 0, 300, 500);// Bottom-left.
1652
+ * // u: 0, v: 500
1653
+ * vertex(0, 50, 0, 0, 500);endShape();`textureMode()` changes the coordinate system for uv coordinates.The parameter, `mode`, accepts two possible constants. If `NORMAL` is
1654
+ * passed, as in `textureMode(NORMAL)`, then the texture’s uv coordinates can
1655
+ * be provided in the range 0 to 1 instead of the image’s dimensions. This can
1656
+ * be helpful for using the same code for multiple images of different sizes.
1657
+ * For example, the code snippet above could be rewritten as follows:// Apply the image as a texture.
1658
+ * texture(img);// Draw the rectangle.
1659
+ * beginShape();// Top-left.
1660
+ * // u: 0, v: 0
1661
+ * vertex(0, 0, 0, 0, 0);// Top-right.
1662
+ * // u: 1, v: 0
1663
+ * vertex(30, 0, 0, 1, 0);// Bottom-right.
1664
+ * // u: 1, v: 1
1665
+ * vertex(30, 50, 0, 1, 1);// Bottom-left.
1666
+ * // u: 0, v: 1
1667
+ * vertex(0, 50, 0, 0, 1);endShape();By default, `mode` is `IMAGE`, which scales uv coordinates to the
1668
+ * dimensions of the image. Calling `textureMode(IMAGE)` applies the default.Note: `textureMode()` can only be used in WebGL mode.
1669
+ *
1670
+ * @param either IMAGE or NORMAL.
1671
+ * @example <div>
1672
+ * <code>
1673
+ * let img;
1674
+ *
1675
+ * async function setup() {
1676
+ * // Load an image and create a p5.Image object.
1677
+ * img = await loadImage('assets/laDefense.jpg');
1678
+ *
1679
+ * createCanvas(100, 100, WEBGL);
1680
+ *
1681
+ * describe('An image of a ceiling against a black background.');
1682
+ * }
1683
+ *
1684
+ * function draw() {
1685
+ * background(0);
1686
+ *
1687
+ * // Apply the image as a texture.
1688
+ * texture(img);
1689
+ *
1690
+ * // Draw the custom shape.
1691
+ * // Use the image's width and height as uv coordinates.
1692
+ * beginShape();
1693
+ * vertex(-30, -30, 0, 0);
1694
+ * vertex(30, -30, img.width, 0);
1695
+ * vertex(30, 30, img.width, img.height);
1696
+ * vertex(-30, 30, 0, img.height);
1697
+ * endShape();
1698
+ * }
1699
+ * </code>
1700
+ * </div>
1701
+ *
1702
+ * <div>
1703
+ * <code>
1704
+ * let img;
1705
+ *
1706
+ * async function setup() {
1707
+ * // Load an image and create a p5.Image object.
1708
+ * img = await loadImage('assets/laDefense.jpg');
1709
+ *
1710
+ * createCanvas(100, 100, WEBGL);
1711
+ *
1712
+ * describe('An image of a ceiling against a black background.');
1713
+ * }
1714
+ *
1715
+ * function draw() {
1716
+ * background(0);
1717
+ *
1718
+ * // Set the texture mode.
1719
+ * textureMode(NORMAL);
1720
+ *
1721
+ * // Apply the image as a texture.
1722
+ * texture(img);
1723
+ *
1724
+ * // Draw the custom shape.
1725
+ * // Use normalized uv coordinates.
1726
+ * beginShape();
1727
+ * vertex(-30, -30, 0, 0);
1728
+ * vertex(30, -30, 1, 0);
1729
+ * vertex(30, 30, 1, 1);
1730
+ * vertex(-30, 30, 0, 1);
1731
+ * endShape();
1732
+ * }
1733
+ * </code>
1734
+ * </div>
1735
+ */
1736
+ function textureMode(mode: IMAGE | NORMAL): void;
1737
+
1738
+ /**
1739
+ * Changes the way textures behave when a shape’s uv coordinates go beyond the
1740
+ * texture.In order for texture() to work, a shape needs a
1741
+ * way to map the points on its surface to the pixels in an image. Built-in
1742
+ * shapes such as rect() and
1743
+ * box() already have these texture mappings based on
1744
+ * their vertices. Custom shapes created with
1745
+ * vertex() require texture mappings to be passed as
1746
+ * uv coordinates.Each call to vertex() must include 5 arguments,
1747
+ * as in `vertex(x, y, z, u, v)`, to map the vertex at coordinates `(x, y, z)`
1748
+ * to the pixel at coordinates `(u, v)` within an image. For example, the
1749
+ * corners of a rectangular image are mapped to the corners of a rectangle by default:`// Apply the image as a texture.
1750
+ * texture(img);
1751
+ *
1752
+ * // Draw the rectangle.
1753
+ * rect(0, 0, 30, 50);`If the image in the code snippet above has dimensions of 300 x 500 pixels,
1754
+ * the same result could be achieved as follows:`// Apply the image as a texture.
1755
+ * texture(img);
1756
+ *
1757
+ * // Draw the rectangle.
1758
+ * beginShape();
1759
+ *
1760
+ * // Top-left.
1761
+ * // u: 0, v: 0
1762
+ * vertex(0, 0, 0, 0, 0);
1763
+ *
1764
+ * // Top-right.
1765
+ * // u: 300, v: 0
1766
+ * vertex(30, 0, 0, 300, 0);
1767
+ *
1768
+ * // Bottom-right.
1769
+ * // u: 300, v: 500
1770
+ * vertex(30, 50, 0, 300, 500);
1771
+ *
1772
+ * // Bottom-left.
1773
+ * // u: 0, v: 500
1774
+ * vertex(0, 50, 0, 0, 500);
1775
+ *
1776
+ * endShape();``textureWrap()` controls how textures behave when their uv's go beyond the
1777
+ * texture. Doing so can produce interesting visual effects such as tiling.
1778
+ * For example, the custom shape above could have u-coordinates are greater
1779
+ * than the image’s width:`// Apply the image as a texture.
1780
+ * texture(img);
1781
+ *
1782
+ * // Draw the rectangle.
1783
+ * beginShape();
1784
+ * vertex(0, 0, 0, 0, 0);
1785
+ *
1786
+ * // Top-right.
1787
+ * // u: 600
1788
+ * vertex(30, 0, 0, 600, 0);
1789
+ *
1790
+ * // Bottom-right.
1791
+ * // u: 600
1792
+ * vertex(30, 50, 0, 600, 500);
1793
+ *
1794
+ * vertex(0, 50, 0, 0, 500);
1795
+ * endShape();`The u-coordinates of 600 are greater than the texture image’s width of 300.
1796
+ * This creates interesting possibilities.The first parameter, `wrapX`, accepts three possible constants. If `CLAMP`
1797
+ * is passed, as in `textureWrap(CLAMP)`, the pixels at the edge of the
1798
+ * texture will extend to the shape’s edges. If `REPEAT` is passed, as in
1799
+ * `textureWrap(REPEAT)`, the texture will tile repeatedly until reaching the
1800
+ * shape’s edges. If `MIRROR` is passed, as in `textureWrap(MIRROR)`, the
1801
+ * texture will tile repeatedly until reaching the shape’s edges, flipping
1802
+ * its orientation between tiles. By default, textures `CLAMP`.The second parameter, `wrapY`, is optional. It accepts the same three
1803
+ * constants, `CLAMP`, `REPEAT`, and `MIRROR`. If one of these constants is
1804
+ * passed, as in `textureWRAP(MIRROR, REPEAT)`, then the texture will `MIRROR`
1805
+ * horizontally and `REPEAT` vertically. By default, `wrapY` will be set to
1806
+ * the same value as `wrapX`.Note: `textureWrap()` can only be used in WebGL mode.
1807
+ *
1808
+ * @param either CLAMP, REPEAT, or MIRROR
1809
+ * @param either CLAMP, REPEAT, or MIRROR
1810
+ * @example <div>
1811
+ * <code>
1812
+ * let img;
1813
+ *
1814
+ * async function setup() {
1815
+ * img = await loadImage('assets/rockies128.jpg');
1816
+ *
1817
+ * createCanvas(100, 100, WEBGL);
1818
+ *
1819
+ * describe(
1820
+ * 'An image of a landscape occupies the top-left corner of a square. Its edge colors smear to cover the other thre quarters of the square.'
1821
+ * );
1822
+ * }
1823
+ *
1824
+ * function draw() {
1825
+ * background(0);
1826
+ *
1827
+ * // Set the texture mode.
1828
+ * textureMode(NORMAL);
1829
+ *
1830
+ * // Set the texture wrapping.
1831
+ * // Note: CLAMP is the default mode.
1832
+ * textureWrap(CLAMP);
1833
+ *
1834
+ * // Apply the image as a texture.
1835
+ * texture(img);
1836
+ *
1837
+ * // Style the shape.
1838
+ * noStroke();
1839
+ *
1840
+ * // Draw the shape.
1841
+ * // Use uv coordinates > 1.
1842
+ * beginShape();
1843
+ * vertex(-30, -30, 0, 0, 0);
1844
+ * vertex(30, -30, 0, 2, 0);
1845
+ * vertex(30, 30, 0, 2, 2);
1846
+ * vertex(-30, 30, 0, 0, 2);
1847
+ * endShape();
1848
+ * }
1849
+ * </code>
1850
+ * </div>
1851
+ *
1852
+ * <div>
1853
+ * <code>
1854
+ * let img;
1855
+ *
1856
+ * async function setup() {
1857
+ * img = await loadImage('assets/rockies128.jpg');
1858
+ *
1859
+ * createCanvas(100, 100, WEBGL);
1860
+ *
1861
+ * describe('Four identical images of a landscape arranged in a grid.');
1862
+ * }
1863
+ *
1864
+ * function draw() {
1865
+ * background(0);
1866
+ *
1867
+ * // Set the texture mode.
1868
+ * textureMode(NORMAL);
1869
+ *
1870
+ * // Set the texture wrapping.
1871
+ * textureWrap(REPEAT);
1872
+ *
1873
+ * // Apply the image as a texture.
1874
+ * texture(img);
1875
+ *
1876
+ * // Style the shape.
1877
+ * noStroke();
1878
+ *
1879
+ * // Draw the shape.
1880
+ * // Use uv coordinates > 1.
1881
+ * beginShape();
1882
+ * vertex(-30, -30, 0, 0, 0);
1883
+ * vertex(30, -30, 0, 2, 0);
1884
+ * vertex(30, 30, 0, 2, 2);
1885
+ * vertex(-30, 30, 0, 0, 2);
1886
+ * endShape();
1887
+ * }
1888
+ * </code>
1889
+ * </div>
1890
+ *
1891
+ * <div>
1892
+ * <code>
1893
+ * let img;
1894
+ *
1895
+ * async function setup() {
1896
+ * img = await loadImage('assets/rockies128.jpg');
1897
+ *
1898
+ * createCanvas(100, 100, WEBGL);
1899
+ *
1900
+ * describe(
1901
+ * 'Four identical images of a landscape arranged in a grid. The images are reflected horizontally and vertically, creating a kaleidoscope effect.'
1902
+ * );
1903
+ * }
1904
+ *
1905
+ * function draw() {
1906
+ * background(0);
1907
+ *
1908
+ * // Set the texture mode.
1909
+ * textureMode(NORMAL);
1910
+ *
1911
+ * // Set the texture wrapping.
1912
+ * textureWrap(MIRROR);
1913
+ *
1914
+ * // Apply the image as a texture.
1915
+ * texture(img);
1916
+ *
1917
+ * // Style the shape.
1918
+ * noStroke();
1919
+ *
1920
+ * // Draw the shape.
1921
+ * // Use uv coordinates > 1.
1922
+ * beginShape();
1923
+ * vertex(-30, -30, 0, 0, 0);
1924
+ * vertex(30, -30, 0, 2, 0);
1925
+ * vertex(30, 30, 0, 2, 2);
1926
+ * vertex(-30, 30, 0, 0, 2);
1927
+ * endShape();
1928
+ * }
1929
+ * </code>
1930
+ * </div>
1931
+ *
1932
+ * <div>
1933
+ * <code>
1934
+ * let img;
1935
+ *
1936
+ * async function setup() {
1937
+ * img = await loadImage('assets/rockies128.jpg');
1938
+ *
1939
+ * createCanvas(100, 100, WEBGL);
1940
+ *
1941
+ * describe(
1942
+ * 'Four identical images of a landscape arranged in a grid. The top row and bottom row are reflections of each other.'
1943
+ * );
1944
+ * }
1945
+ *
1946
+ * function draw() {
1947
+ * background(0);
1948
+ *
1949
+ * // Set the texture mode.
1950
+ * textureMode(NORMAL);
1951
+ *
1952
+ * // Set the texture wrapping.
1953
+ * textureWrap(REPEAT, MIRROR);
1954
+ *
1955
+ * // Apply the image as a texture.
1956
+ * texture(img);
1957
+ *
1958
+ * // Style the shape.
1959
+ * noStroke();
1960
+ *
1961
+ * // Draw the shape.
1962
+ * // Use uv coordinates > 1.
1963
+ * beginShape();
1964
+ * vertex(-30, -30, 0, 0, 0);
1965
+ * vertex(30, -30, 0, 2, 0);
1966
+ * vertex(30, 30, 0, 2, 2);
1967
+ * vertex(-30, 30, 0, 0, 2);
1968
+ * endShape();
1969
+ * }
1970
+ * </code>
1971
+ * </div>
1972
+ */
1973
+ function textureWrap(wrapX: CLAMP | REPEAT | MIRROR, wrapY: CLAMP | REPEAT | MIRROR): void;
1974
+
1975
+ /**
1976
+ * Sets the current material as a normal material.A normal material sets surfaces facing the x-axis to red, those facing the
1977
+ * y-axis to green, and those facing the z-axis to blue. Normal material isn't
1978
+ * affected by light. It’s often used as a placeholder material when debugging.Note: `normalMaterial()` can only be used in WebGL mode.
1979
+ *
1980
+ * @example <div>
1981
+ * <code>
1982
+ * // Click and drag the mouse to view the scene from different angles.
1983
+ *
1984
+ * function setup() {
1985
+ * createCanvas(100, 100, WEBGL);
1986
+ *
1987
+ * describe('A multicolor torus drawn on a gray background.');
1988
+ * }
1989
+ *
1990
+ * function draw() {
1991
+ * background(200);
1992
+ *
1993
+ * // Enable orbiting with the mouse.
1994
+ * orbitControl();
1995
+ *
1996
+ * // Style the torus.
1997
+ * normalMaterial();
1998
+ *
1999
+ * // Draw the torus.
2000
+ * torus(30);
2001
+ * }
2002
+ * </code>
2003
+ * </div>
2004
+ */
2005
+ function normalMaterial(): void;
2006
+
2007
+ /**
2008
+ * Sets the ambient color of shapes’ surface material.The `ambientMaterial()` color sets the components of the
2009
+ * ambientLight() color that shapes will
2010
+ * reflect. For example, calling `ambientMaterial(255, 255, 0)` would cause a
2011
+ * shape to reflect red and green light, but not blue light.`ambientMaterial()` can be called three ways with different parameters to
2012
+ * set the material’s color.The first way to call `ambientMaterial()` has one parameter, `gray`.
2013
+ * Grayscale values between 0 and 255, as in `ambientMaterial(50)`, can be
2014
+ * passed to set the material’s color. Higher grayscale values make shapes
2015
+ * appear brighter.The second way to call `ambientMaterial()` has one parameter, `color`. A
2016
+ * p5.Color object, an array of color values, or a
2017
+ * CSS color string, as in `ambientMaterial('magenta')`, can be passed to set
2018
+ * the material’s color.The third way to call `ambientMaterial()` has three parameters, `v1`, `v2`,
2019
+ * and `v3`. RGB, HSB, or HSL values, as in `ambientMaterial(255, 0, 0)`, can
2020
+ * be passed to set the material’s colors. Color values will be interpreted
2021
+ * using the current colorMode().Note: `ambientMaterial()` can only be used in WebGL mode.
2022
+ *
2023
+ * @param red or hue value in the current
2024
+ * <a href="#/p5/colorMode">colorMode()</a>.
2025
+ * @param green or saturation value in the
2026
+ * current <a href="#/p5/colorMode">colorMode()</a>.
2027
+ * @param blue, brightness, or lightness value in the
2028
+ * current <a href="#/p5/colorMode">colorMode()</a>.
2029
+ * @example <div>
2030
+ * <code>
2031
+ * // Click and drag the mouse to view the scene from different angles.
2032
+ *
2033
+ * function setup() {
2034
+ * createCanvas(100, 100, WEBGL);
2035
+ *
2036
+ * describe('A magenta cube drawn on a gray background.');
2037
+ * }
2038
+ *
2039
+ * function draw() {
2040
+ * background(200);
2041
+ *
2042
+ * // Enable orbiting with the mouse.
2043
+ * orbitControl();
2044
+ *
2045
+ * // Turn on a magenta ambient light.
2046
+ * ambientLight(255, 0, 255);
2047
+ *
2048
+ * // Draw the box.
2049
+ * box();
2050
+ * }
2051
+ * </code>
2052
+ * </div>
2053
+ *
2054
+ * <div>
2055
+ * <code>
2056
+ * // Click and drag the mouse to view the scene from different angles.
2057
+ *
2058
+ * function setup() {
2059
+ * createCanvas(100, 100, WEBGL);
2060
+ *
2061
+ * describe('A purple cube drawn on a gray background.');
2062
+ * }
2063
+ *
2064
+ * function draw() {
2065
+ * background(200);
2066
+ *
2067
+ * // Enable orbiting with the mouse.
2068
+ * orbitControl();
2069
+ *
2070
+ * // Turn on a magenta ambient light.
2071
+ * ambientLight(255, 0, 255);
2072
+ *
2073
+ * // Add a dark gray ambient material.
2074
+ * ambientMaterial(150);
2075
+ *
2076
+ * // Draw the box.
2077
+ * box();
2078
+ * }
2079
+ * </code>
2080
+ * </div>
2081
+ *
2082
+ * <div>
2083
+ * <code>
2084
+ * // Click and drag the mouse to view the scene from different angles.
2085
+ *
2086
+ * function setup() {
2087
+ * createCanvas(100, 100, WEBGL);
2088
+ *
2089
+ * describe('A red cube drawn on a gray background.');
2090
+ * }
2091
+ *
2092
+ * function draw() {
2093
+ * background(200);
2094
+ *
2095
+ * // Enable orbiting with the mouse.
2096
+ * orbitControl();
2097
+ *
2098
+ * // Turn on a magenta ambient light.
2099
+ * ambientLight(255, 0, 255);
2100
+ *
2101
+ * // Add a yellow ambient material using RGB values.
2102
+ * ambientMaterial(255, 255, 0);
2103
+ *
2104
+ * // Draw the box.
2105
+ * box();
2106
+ * }
2107
+ * </code>
2108
+ * </div>
2109
+ *
2110
+ * <div>
2111
+ * <code>
2112
+ * // Click and drag the mouse to view the scene from different angles.
2113
+ *
2114
+ * function setup() {
2115
+ * createCanvas(100, 100, WEBGL);
2116
+ *
2117
+ * describe('A red cube drawn on a gray background.');
2118
+ * }
2119
+ *
2120
+ * function draw() {
2121
+ * background(200);
2122
+ *
2123
+ * // Enable orbiting with the mouse.
2124
+ * orbitControl();
2125
+ *
2126
+ * // Turn on a magenta ambient light.
2127
+ * ambientLight(255, 0, 255);
2128
+ *
2129
+ * // Add a yellow ambient material using a p5.Color object.
2130
+ * let c = color(255, 255, 0);
2131
+ * ambientMaterial(c);
2132
+ *
2133
+ * // Draw the box.
2134
+ * box();
2135
+ * }
2136
+ * </code>
2137
+ * </div>
2138
+ *
2139
+ * <div>
2140
+ * <code>
2141
+ * // Click and drag the mouse to view the scene from different angles.
2142
+ *
2143
+ * function setup() {
2144
+ * createCanvas(100, 100, WEBGL);
2145
+ *
2146
+ * describe('A red cube drawn on a gray background.');
2147
+ * }
2148
+ *
2149
+ * function draw() {
2150
+ * background(200);
2151
+ *
2152
+ * // Enable orbiting with the mouse.
2153
+ * orbitControl();
2154
+ *
2155
+ * // Turn on a magenta ambient light.
2156
+ * ambientLight(255, 0, 255);
2157
+ *
2158
+ * // Add a yellow ambient material using a color string.
2159
+ * ambientMaterial('yellow');
2160
+ *
2161
+ * // Draw the box.
2162
+ * box();
2163
+ * }
2164
+ * </code>
2165
+ * </div>
2166
+ *
2167
+ * <div>
2168
+ * <code>
2169
+ * // Click and drag the mouse to view the scene from different angles.
2170
+ *
2171
+ * function setup() {
2172
+ * createCanvas(100, 100, WEBGL);
2173
+ *
2174
+ * describe('A yellow cube drawn on a gray background.');
2175
+ * }
2176
+ *
2177
+ * function draw() {
2178
+ * background(200);
2179
+ *
2180
+ * // Enable orbiting with the mouse.
2181
+ * orbitControl();
2182
+ *
2183
+ * // Turn on a white ambient light.
2184
+ * ambientLight(255, 255, 255);
2185
+ *
2186
+ * // Add a yellow ambient material using a color string.
2187
+ * ambientMaterial('yellow');
2188
+ *
2189
+ * // Draw the box.
2190
+ * box();
2191
+ * }
2192
+ * </code>
2193
+ * </div>
2194
+ */
2195
+ function ambientMaterial(v1: number, v2: number, v3: number): void;
2196
+
2197
+ /**
2198
+ * @param grayscale value between 0 (black) and 255 (white).
2199
+ */
2200
+ function ambientMaterial(gray: number): void;
2201
+
2202
+ /**
2203
+ * @param color as a <a href="#/p5.Color">p5.Color</a> object,
2204
+ * an array of color values, or a CSS string.
2205
+ */
2206
+ function ambientMaterial(color: p5.Color | number[] | string): void;
2207
+
2208
+ /**
2209
+ * Sets the emissive color of shapes’ surface material.The `emissiveMaterial()` color sets a color shapes display at full
2210
+ * strength, regardless of lighting. This can give the appearance that a shape
2211
+ * is glowing. However, emissive materials don’t actually emit light that
2212
+ * can affect surrounding objects.`emissiveMaterial()` can be called three ways with different parameters to
2213
+ * set the material’s color.The first way to call `emissiveMaterial()` has one parameter, `gray`.
2214
+ * Grayscale values between 0 and 255, as in `emissiveMaterial(50)`, can be
2215
+ * passed to set the material’s color. Higher grayscale values make shapes
2216
+ * appear brighter.The second way to call `emissiveMaterial()` has one parameter, `color`. A
2217
+ * p5.Color object, an array of color values, or a
2218
+ * CSS color string, as in `emissiveMaterial('magenta')`, can be passed to set
2219
+ * the material’s color.The third way to call `emissiveMaterial()` has four parameters, `v1`, `v2`,
2220
+ * `v3`, and `alpha`. `alpha` is optional. RGBA, HSBA, or HSLA values can be
2221
+ * passed to set the material’s colors, as in `emissiveMaterial(255, 0, 0)` or
2222
+ * `emissiveMaterial(255, 0, 0, 30)`. Color values will be interpreted using
2223
+ * the current colorMode().Note: `emissiveMaterial()` can only be used in WebGL mode.
2224
+ *
2225
+ * @param red or hue value in the current
2226
+ * <a href="#/p5/colorMode">colorMode()</a>.
2227
+ * @param green or saturation value in the
2228
+ * current <a href="#/p5/colorMode">colorMode()</a>.
2229
+ * @param blue, brightness, or lightness value in the
2230
+ * current <a href="#/p5/colorMode">colorMode()</a>.
2231
+ * @param alpha value in the current
2232
+ * <a href="#/p5/colorMode">colorMode()</a>.
2233
+ * @example <div>
2234
+ * <code>
2235
+ * // Click and drag the mouse to view the scene from different angles.
2236
+ *
2237
+ * function setup() {
2238
+ * createCanvas(100, 100, WEBGL);
2239
+ *
2240
+ * describe('A red cube drawn on a gray background.');
2241
+ * }
2242
+ *
2243
+ * function draw() {
2244
+ * background(200);
2245
+ *
2246
+ * // Enable orbiting with the mouse.
2247
+ * orbitControl();
2248
+ *
2249
+ * // Turn on a white ambient light.
2250
+ * ambientLight(255, 255, 255);
2251
+ *
2252
+ * // Add a red emissive material using RGB values.
2253
+ * emissiveMaterial(255, 0, 0);
2254
+ *
2255
+ * // Draw the box.
2256
+ * box();
2257
+ * }
2258
+ * </code>
2259
+ * </div>
2260
+ */
2261
+ function emissiveMaterial(v1: number, v2: number, v3: number, alpha?: number): void;
2262
+
2263
+ /**
2264
+ * @param grayscale value between 0 (black) and 255 (white).
2265
+ */
2266
+ function emissiveMaterial(gray: number): void;
2267
+
2268
+ /**
2269
+ * @param color as a <a href="#/p5.Color">p5.Color</a> object,
2270
+ * an array of color values, or a CSS string.
2271
+ */
2272
+ function emissiveMaterial(color: p5.Color | number[] | string): void;
2273
+
2274
+ /**
2275
+ * Sets the specular color of shapes’ surface material.The `specularMaterial()` color sets the components of light color that
2276
+ * glossy coats on shapes will reflect. For example, calling
2277
+ * `specularMaterial(255, 255, 0)` would cause a shape to reflect red and
2278
+ * green light, but not blue light.Unlike ambientMaterial(),
2279
+ * `specularMaterial()` will reflect the full color of light sources including
2280
+ * directionalLight(),
2281
+ * pointLight(),
2282
+ * and spotLight(). This is what gives it shapes
2283
+ * their "shiny" appearance. The material’s shininess can be controlled by the
2284
+ * shininess() function.`specularMaterial()` can be called three ways with different parameters to
2285
+ * set the material’s color.The first way to call `specularMaterial()` has one parameter, `gray`.
2286
+ * Grayscale values between 0 and 255, as in `specularMaterial(50)`, can be
2287
+ * passed to set the material’s color. Higher grayscale values make shapes
2288
+ * appear brighter.The second way to call `specularMaterial()` has one parameter, `color`. A
2289
+ * p5.Color> object, an array of color values, or a CSS
2290
+ * color string, as in `specularMaterial('magenta')`, can be passed to set the
2291
+ * material’s color.The third way to call `specularMaterial()` has four parameters, `v1`, `v2`,
2292
+ * `v3`, and `alpha`. `alpha` is optional. RGBA, HSBA, or HSLA values can be
2293
+ * passed to set the material’s colors, as in `specularMaterial(255, 0, 0)` or
2294
+ * `specularMaterial(255, 0, 0, 30)`. Color values will be interpreted using
2295
+ * the current colorMode().
2296
+ *
2297
+ * @param grayscale value between 0 (black) and 255 (white).
2298
+ * @param alpha value in the current current
2299
+ * <a href="#/p5/colorMode">colorMode()</a>.
2300
+ * @example <div>
2301
+ * <code>
2302
+ * // Click and drag the mouse to view the scene from different angles.
2303
+ * // Double-click the canvas to apply a specular material.
2304
+ *
2305
+ * let isGlossy = false;
2306
+ *
2307
+ * function setup() {
2308
+ * createCanvas(100, 100, WEBGL);
2309
+ *
2310
+ * describe('A red torus drawn on a gray background. It becomes glossy when the user double-clicks.');
2311
+ * }
2312
+ *
2313
+ * function draw() {
2314
+ * background(200);
2315
+ *
2316
+ * // Enable orbiting with the mouse.
2317
+ * orbitControl();
2318
+ *
2319
+ * // Turn on a white point light at the top-right.
2320
+ * pointLight(255, 255, 255, 30, -40, 30);
2321
+ *
2322
+ * // Add a glossy coat if the user has double-clicked.
2323
+ * if (isGlossy === true) {
2324
+ * specularMaterial(255);
2325
+ * shininess(50);
2326
+ * }
2327
+ *
2328
+ * // Style the torus.
2329
+ * noStroke();
2330
+ * fill(255, 0, 0);
2331
+ *
2332
+ * // Draw the torus.
2333
+ * torus(30);
2334
+ * }
2335
+ *
2336
+ * // Make the torus glossy when the user double-clicks.
2337
+ * function doubleClicked() {
2338
+ * isGlossy = true;
2339
+ * }
2340
+ * </code>
2341
+ * </div>
2342
+ *
2343
+ * <div>
2344
+ * <code>
2345
+ * // Click and drag the mouse to view the scene from different angles.
2346
+ * // Double-click the canvas to apply a specular material.
2347
+ *
2348
+ * let isGlossy = false;
2349
+ *
2350
+ * function setup() {
2351
+ * createCanvas(100, 100, WEBGL);
2352
+ *
2353
+ * describe(
2354
+ * 'A red torus drawn on a gray background. It becomes glossy and reflects green light when the user double-clicks.'
2355
+ * );
2356
+ * }
2357
+ *
2358
+ * function draw() {
2359
+ * background(200);
2360
+ *
2361
+ * // Enable orbiting with the mouse.
2362
+ * orbitControl();
2363
+ *
2364
+ * // Turn on a white point light at the top-right.
2365
+ * pointLight(255, 255, 255, 30, -40, 30);
2366
+ *
2367
+ * // Add a glossy green coat if the user has double-clicked.
2368
+ * if (isGlossy === true) {
2369
+ * specularMaterial(0, 255, 0);
2370
+ * shininess(50);
2371
+ * }
2372
+ *
2373
+ * // Style the torus.
2374
+ * noStroke();
2375
+ * fill(255, 0, 0);
2376
+ *
2377
+ * // Draw the torus.
2378
+ * torus(30);
2379
+ * }
2380
+ *
2381
+ * // Make the torus glossy when the user double-clicks.
2382
+ * function doubleClicked() {
2383
+ * isGlossy = true;
2384
+ * }
2385
+ * </code>
2386
+ * </div>
2387
+ *
2388
+ * <div>
2389
+ * <code>
2390
+ * // Click and drag the mouse to view the scene from different angles.
2391
+ * // Double-click the canvas to apply a specular material.
2392
+ *
2393
+ * let isGlossy = false;
2394
+ *
2395
+ * function setup() {
2396
+ * createCanvas(100, 100, WEBGL);
2397
+ *
2398
+ * describe(
2399
+ * 'A red torus drawn on a gray background. It becomes glossy and reflects green light when the user double-clicks.'
2400
+ * );
2401
+ * }
2402
+ *
2403
+ * function draw() {
2404
+ * background(200);
2405
+ *
2406
+ * // Enable orbiting with the mouse.
2407
+ * orbitControl();
2408
+ *
2409
+ * // Turn on a white point light at the top-right.
2410
+ * pointLight(255, 255, 255, 30, -40, 30);
2411
+ *
2412
+ * // Add a glossy green coat if the user has double-clicked.
2413
+ * if (isGlossy === true) {
2414
+ * // Create a p5.Color object.
2415
+ * let c = color('green');
2416
+ * specularMaterial(c);
2417
+ * shininess(50);
2418
+ * }
2419
+ *
2420
+ * // Style the torus.
2421
+ * noStroke();
2422
+ * fill(255, 0, 0);
2423
+ *
2424
+ * // Draw the torus.
2425
+ * torus(30);
2426
+ * }
2427
+ *
2428
+ * // Make the torus glossy when the user double-clicks.
2429
+ * function doubleClicked() {
2430
+ * isGlossy = true;
2431
+ * }
2432
+ * </code>
2433
+ * </div>
2434
+ *
2435
+ * <div>
2436
+ * <code>
2437
+ * // Click and drag the mouse to view the scene from different angles.
2438
+ * // Double-click the canvas to apply a specular material.
2439
+ *
2440
+ * let isGlossy = false;
2441
+ *
2442
+ * function setup() {
2443
+ * createCanvas(100, 100, WEBGL);
2444
+ *
2445
+ * describe(
2446
+ * 'A red torus drawn on a gray background. It becomes glossy and reflects green light when the user double-clicks.'
2447
+ * );
2448
+ * }
2449
+ *
2450
+ * function draw() {
2451
+ * background(200);
2452
+ *
2453
+ * // Enable orbiting with the mouse.
2454
+ * orbitControl();
2455
+ *
2456
+ * // Turn on a white point light at the top-right.
2457
+ * pointLight(255, 255, 255, 30, -40, 30);
2458
+ *
2459
+ * // Add a glossy green coat if the user has double-clicked.
2460
+ * if (isGlossy === true) {
2461
+ * specularMaterial('#00FF00');
2462
+ * shininess(50);
2463
+ * }
2464
+ *
2465
+ * // Style the torus.
2466
+ * noStroke();
2467
+ * fill(255, 0, 0);
2468
+ *
2469
+ * // Draw the torus.
2470
+ * torus(30);
2471
+ * }
2472
+ *
2473
+ * // Make the torus glossy when the user double-clicks.
2474
+ * function doubleClicked() {
2475
+ * isGlossy = true;
2476
+ * }
2477
+ * </code>
2478
+ * </div>
2479
+ */
2480
+ function specularMaterial(gray: number, alpha?: number): void;
2481
+
2482
+ /**
2483
+ * @param red or hue value in
2484
+ * the current <a href="#/p5/colorMode">colorMode()</a>.
2485
+ * @param green or saturation value
2486
+ * in the current <a href="#/p5/colorMode">colorMode()</a>.
2487
+ * @param blue, brightness, or lightness value
2488
+ * in the current <a href="#/p5/colorMode">colorMode()</a>.
2489
+ */
2490
+ function specularMaterial(v1: number, v2: number, v3: number, alpha?: number): void;
2491
+
2492
+ /**
2493
+ * @param color as a <a href="#/p5.Color">p5.Color</a> object,
2494
+ * an array of color values, or a CSS string.
2495
+ */
2496
+ function specularMaterial(color: p5.Color | number[] | string): void;
2497
+
2498
+ /**
2499
+ * Sets the amount of gloss ("shininess") of a
2500
+ * specularMaterial().Shiny materials focus reflected light more than dull materials.
2501
+ * `shininess()` affects the way materials reflect light sources including
2502
+ * directionalLight(),
2503
+ * pointLight(),
2504
+ * and spotLight().The parameter, `shine`, is a number that sets the amount of shininess.
2505
+ * `shine` must be greater than 1, which is its default value.
2506
+ *
2507
+ * @param amount of shine.
2508
+ * @example <div>
2509
+ * <code>
2510
+ * function setup() {
2511
+ * createCanvas(100, 100, WEBGL);
2512
+ *
2513
+ * describe(
2514
+ * 'Two red spheres drawn on a gray background. White light reflects from their surfaces as the mouse moves. The right sphere is shinier than the left sphere.'
2515
+ * );
2516
+ * }
2517
+ *
2518
+ * function draw() {
2519
+ * background(200);
2520
+ *
2521
+ * // Turn on a red ambient light.
2522
+ * ambientLight(255, 0, 0);
2523
+ *
2524
+ * // Get the mouse's coordinates.
2525
+ * let mx = mouseX - 50;
2526
+ * let my = mouseY - 50;
2527
+ *
2528
+ * // Turn on a white point light that follows the mouse.
2529
+ * pointLight(255, 255, 255, mx, my, 50);
2530
+ *
2531
+ * // Style the sphere.
2532
+ * noStroke();
2533
+ *
2534
+ * // Add a specular material with a grayscale value.
2535
+ * specularMaterial(255);
2536
+ *
2537
+ * // Draw the left sphere with low shininess.
2538
+ * translate(-25, 0, 0);
2539
+ * shininess(10);
2540
+ * sphere(20);
2541
+ *
2542
+ * // Draw the right sphere with high shininess.
2543
+ * translate(50, 0, 0);
2544
+ * shininess(100);
2545
+ * sphere(20);
2546
+ * }
2547
+ * </code>
2548
+ * </div>
2549
+ */
2550
+ function shininess(shine: number): void;
2551
+
2552
+ /**
2553
+ * Sets the amount of "metalness" of a
2554
+ * specularMaterial().`metalness()` can make materials appear more metallic. It affects the way
2555
+ * materials reflect light sources including
2556
+ * affects the way materials reflect light sources including
2557
+ * directionalLight(),
2558
+ * pointLight(),
2559
+ * spotLight(), and
2560
+ * imageLight().The parameter, `metallic`, is a number that sets the amount of metalness.
2561
+ * `metallic` must be greater than 1, which is its default value. Higher
2562
+ * values, such as `metalness(100)`, make specular materials appear more
2563
+ * metallic.
2564
+ *
2565
+ * @param amount of metalness.
2566
+ * @example <div>
2567
+ * <code>
2568
+ * function setup() {
2569
+ * createCanvas(100, 100, WEBGL);
2570
+ *
2571
+ * describe(
2572
+ * 'Two blue spheres drawn on a gray background. White light reflects from their surfaces as the mouse moves. The right sphere is more metallic than the left sphere.'
2573
+ * );
2574
+ * }
2575
+ *
2576
+ * function draw() {
2577
+ * background(200);
2578
+ *
2579
+ * // Turn on an ambient light.
2580
+ * ambientLight(200);
2581
+ *
2582
+ * // Get the mouse's coordinates.
2583
+ * let mx = mouseX - 50;
2584
+ * let my = mouseY - 50;
2585
+ *
2586
+ * // Turn on a white point light that follows the mouse.
2587
+ * pointLight(255, 255, 255, mx, my, 50);
2588
+ *
2589
+ * // Style the spheres.
2590
+ * noStroke();
2591
+ * fill(30, 30, 255);
2592
+ * specularMaterial(255);
2593
+ * shininess(20);
2594
+ *
2595
+ * // Draw the left sphere with low metalness.
2596
+ * translate(-25, 0, 0);
2597
+ * metalness(1);
2598
+ * sphere(20);
2599
+ *
2600
+ * // Draw the right sphere with high metalness.
2601
+ * translate(50, 0, 0);
2602
+ * metalness(50);
2603
+ * sphere(20);
2604
+ * }
2605
+ * </code>
2606
+ * </div>
2607
+ *
2608
+ * <div>
2609
+ * <code>
2610
+ * // Click and drag the mouse to view the scene from different angles.
2611
+ *
2612
+ * let img;
2613
+ *
2614
+ * async function setup() {
2615
+ * img = await loadImage('assets/outdoor_spheremap.jpg');
2616
+ *
2617
+ * createCanvas(100 ,100 ,WEBGL);
2618
+ *
2619
+ * describe(
2620
+ * 'Two spheres floating above a landscape. The surface of the spheres reflect the landscape. The right sphere is more reflective than the left sphere.'
2621
+ * );
2622
+ * }
2623
+ *
2624
+ * function draw() {
2625
+ * // Add the panorama.
2626
+ * panorama(img);
2627
+ *
2628
+ * // Enable orbiting with the mouse.
2629
+ * orbitControl();
2630
+ *
2631
+ * // Use the image as a light source.
2632
+ * imageLight(img);
2633
+ *
2634
+ * // Style the spheres.
2635
+ * noStroke();
2636
+ * specularMaterial(50);
2637
+ * shininess(200);
2638
+ *
2639
+ * // Draw the left sphere with low metalness.
2640
+ * translate(-25, 0, 0);
2641
+ * metalness(1);
2642
+ * sphere(20);
2643
+ *
2644
+ * // Draw the right sphere with high metalness.
2645
+ * translate(50, 0, 0);
2646
+ * metalness(50);
2647
+ * sphere(20);
2648
+ * }
2649
+ * </code>
2650
+ * </div>
2651
+ */
2652
+ function metalness(metallic: number): void;
2653
+
2654
+ }
2655
+
2656
+ export default function material(p5: any, fn: any): void;