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,660 @@
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
+ class Shader {
8
+ constructor(renderer: p5.RendererGL, vertSrc: string, fragSrc: string, options?: object);
9
+
10
+ /**
11
+ * Shaders are written in GLSL, but
12
+ * there are different versions of GLSL that it might be written in.Calling this method on a `p5.Shader` will return the GLSL version it uses, either `100 es` or `300 es`.
13
+ * WebGL 1 shaders will only use `100 es`, and WebGL 2 shaders may use either.
14
+ */
15
+ version(): string;
16
+
17
+ /**
18
+ * Logs the hooks available in this shader, and their current implementation.Each shader may let you override bits of its behavior. Each bit is called
19
+ * a A hook is either for the shader, if it affects the
20
+ * position of vertices, or in the shader, if it affects the pixel
21
+ * color. This method logs those values to the console, letting you know what
22
+ * you are able to use in a call to
23
+ * `modify()`.For example, this shader will produce the following output:`myShader = baseMaterialShader().modify({
24
+ * declarations: 'uniform float time;',
25
+ * 'vec3 getWorldPosition': `(vec3 pos) {
26
+ * pos.y += 20. * sin(time * 0.001 + pos.x * 0.05);
27
+ * return pos;
28
+ * }`
29
+ * });
30
+ * myShader.inspectHooks();``==== Vertex shader hooks: ====
31
+ * void beforeVertex() {}
32
+ * vec3 getLocalPosition(vec3 position) { return position; }
33
+ * [MODIFIED] vec3 getWorldPosition(vec3 pos) {
34
+ * pos.y += 20. * sin(time * 0.001 + pos.x * 0.05);
35
+ * return pos;
36
+ * }
37
+ * vec3 getLocalNormal(vec3 normal) { return normal; }
38
+ * vec3 getWorldNormal(vec3 normal) { return normal; }
39
+ * vec2 getUV(vec2 uv) { return uv; }
40
+ * vec4 getVertexColor(vec4 color) { return color; }
41
+ * void afterVertex() {}
42
+ *
43
+ * ==== Fragment shader hooks: ====
44
+ * void beforeFragment() {}
45
+ * Inputs getPixelInputs(Inputs inputs) { return inputs; }
46
+ * vec4 combineColors(ColorComponents components) {
47
+ * vec4 color = vec4(0.);
48
+ * color.rgb += components.diffuse * components.baseColor;
49
+ * color.rgb += components.ambient * components.ambientColor;
50
+ * color.rgb += components.specular * components.specularColor;
51
+ * color.rgb += components.emissive;
52
+ * color.a = components.opacity;
53
+ * return color;
54
+ * }
55
+ * vec4 getFinalColor(vec4 color) { return color; }
56
+ * void afterFragment() {}`
57
+ */
58
+ inspectHooks(): void;
59
+
60
+ /**
61
+ * Returns a new shader, based on the original, but with custom snippets
62
+ * of shader code replacing default behaviour.Each shader may let you override bits of its behavior. Each bit is called
63
+ * a A hook is either for the shader, if it affects the
64
+ * position of vertices, or in the shader, if it affects the pixel
65
+ * color. You can inspect the different hooks available by calling
66
+ * `yourShader.inspectHooks()`. You can
67
+ * also read the reference for the default material, normal material, color, line, and point shaders to
68
+ * see what hooks they have available.`modify()` takes one parameter, `hooks`, an object with the hooks you want
69
+ * to override. Each key of the `hooks` object is the name
70
+ * of a hook, and the value is a string with the GLSL code for your hook.If you supply functions that aren't existing hooks, they will get added at the start of
71
+ * the shader as helper functions so that you can use them in your hooks.To add new uniforms to your shader, you can pass in a `uniforms` object containing
72
+ * the type and name of the uniform as the key, and a default value or function returning
73
+ * a default value as its value. These will be automatically set when the shader is set
74
+ * with `shader(yourShader)`.You can also add a `declarations` key, where the value is a GLSL string declaring
75
+ * custom uniform variables, globals, and functions shared
76
+ * between hooks. To add declarations just in a vertex or fragment shader, add
77
+ * `vertexDeclarations` and `fragmentDeclarations` keys.
78
+ *
79
+ * @param
80
+ */
81
+ modify(hooks: object): p5.Shader;
82
+
83
+ /**
84
+ * Copies the shader from one drawing context to another.Each `p5.Shader` object must be compiled by calling
85
+ * shader() before it can run. Compilation happens
86
+ * in a drawing context which is usually the main canvas or an instance of
87
+ * p5.Graphics. A shader can only be used in the
88
+ * context where it was compiled. The `copyToContext()` method compiles the
89
+ * shader again and copies it to another drawing context where it can be
90
+ * reused.The parameter, `context`, is the drawing context where the shader will be
91
+ * used. The shader can be copied to an instance of
92
+ * p5.Graphics, as in
93
+ * `myShader.copyToContext(pg)`. The shader can also be copied from a
94
+ * p5.Graphics object to the main canvas using
95
+ * the `p5.instance` variable, as in `myShader.copyToContext(p5.instance)`.Note: A p5.Shader object created with
96
+ * createShader(),
97
+ * createFilterShader(), or
98
+ * loadShader()
99
+ * can be used directly with a p5.Framebuffer
100
+ * object created with
101
+ * createFramebuffer(). Both objects
102
+ * have the same context as the main canvas.
103
+ *
104
+ * @param
105
+ */
106
+ copyToContext(context: p5 | p5.Graphics): p5.Shader;
107
+
108
+ /**
109
+ * Sets the shader’s uniform (global) variables.Shader programs run on the computer’s graphics processing unit (GPU).
110
+ * They live in part of the computer’s memory that’s completely separate
111
+ * from the sketch that runs them. Uniforms are global variables within a
112
+ * shader program. They provide a way to pass values from a sketch running
113
+ * on the CPU to a shader program running on the GPU.The first parameter, `uniformName`, is a string with the uniform’s name.
114
+ * For the shader above, `uniformName` would be `'r'`.The second parameter, `data`, is the value that should be used to set the
115
+ * uniform. For example, calling `myShader.setUniform('r', 0.5)` would set
116
+ * the `r` uniform in the shader above to `0.5`. data should match the
117
+ * uniform’s type. Numbers, strings, booleans, arrays, and many types of
118
+ * images can all be passed to a shader with `setUniform()`.
119
+ *
120
+ * @param
121
+ * @param
122
+ */
123
+ setUniform(uniformName: string, data: boolean | number | number[] | p5.Image | p5.Graphics | p5.MediaElement | p5.Texture): void;
124
+
125
+ }
126
+
127
+ /**
128
+ * Shaders are written in GLSL, but
129
+ * there are different versions of GLSL that it might be written in.Calling this method on a `p5.Shader` will return the GLSL version it uses, either `100 es` or `300 es`.
130
+ * WebGL 1 shaders will only use `100 es`, and WebGL 2 shaders may use either.
131
+ *
132
+ * @returns The GLSL version used by the shader.
133
+ */
134
+ function version(): string;
135
+
136
+ /**
137
+ * Logs the hooks available in this shader, and their current implementation.Each shader may let you override bits of its behavior. Each bit is called
138
+ * a A hook is either for the shader, if it affects the
139
+ * position of vertices, or in the shader, if it affects the pixel
140
+ * color. This method logs those values to the console, letting you know what
141
+ * you are able to use in a call to
142
+ * `modify()`.For example, this shader will produce the following output:`myShader = baseMaterialShader().modify({
143
+ * declarations: 'uniform float time;',
144
+ * 'vec3 getWorldPosition': `(vec3 pos) {
145
+ * pos.y += 20. * sin(time * 0.001 + pos.x * 0.05);
146
+ * return pos;
147
+ * }`
148
+ * });
149
+ * myShader.inspectHooks();``==== Vertex shader hooks: ====
150
+ * void beforeVertex() {}
151
+ * vec3 getLocalPosition(vec3 position) { return position; }
152
+ * [MODIFIED] vec3 getWorldPosition(vec3 pos) {
153
+ * pos.y += 20. * sin(time * 0.001 + pos.x * 0.05);
154
+ * return pos;
155
+ * }
156
+ * vec3 getLocalNormal(vec3 normal) { return normal; }
157
+ * vec3 getWorldNormal(vec3 normal) { return normal; }
158
+ * vec2 getUV(vec2 uv) { return uv; }
159
+ * vec4 getVertexColor(vec4 color) { return color; }
160
+ * void afterVertex() {}
161
+ *
162
+ * ==== Fragment shader hooks: ====
163
+ * void beforeFragment() {}
164
+ * Inputs getPixelInputs(Inputs inputs) { return inputs; }
165
+ * vec4 combineColors(ColorComponents components) {
166
+ * vec4 color = vec4(0.);
167
+ * color.rgb += components.diffuse * components.baseColor;
168
+ * color.rgb += components.ambient * components.ambientColor;
169
+ * color.rgb += components.specular * components.specularColor;
170
+ * color.rgb += components.emissive;
171
+ * color.a = components.opacity;
172
+ * return color;
173
+ * }
174
+ * vec4 getFinalColor(vec4 color) { return color; }
175
+ * void afterFragment() {}`
176
+ *
177
+ */
178
+ function inspectHooks(): void;
179
+
180
+ /**
181
+ * Returns a new shader, based on the original, but with custom snippets
182
+ * of shader code replacing default behaviour.Each shader may let you override bits of its behavior. Each bit is called
183
+ * a A hook is either for the shader, if it affects the
184
+ * position of vertices, or in the shader, if it affects the pixel
185
+ * color. You can inspect the different hooks available by calling
186
+ * `yourShader.inspectHooks()`. You can
187
+ * also read the reference for the default material, normal material, color, line, and point shaders to
188
+ * see what hooks they have available.`modify()` takes one parameter, `hooks`, an object with the hooks you want
189
+ * to override. Each key of the `hooks` object is the name
190
+ * of a hook, and the value is a string with the GLSL code for your hook.If you supply functions that aren't existing hooks, they will get added at the start of
191
+ * the shader as helper functions so that you can use them in your hooks.To add new uniforms to your shader, you can pass in a `uniforms` object containing
192
+ * the type and name of the uniform as the key, and a default value or function returning
193
+ * a default value as its value. These will be automatically set when the shader is set
194
+ * with `shader(yourShader)`.You can also add a `declarations` key, where the value is a GLSL string declaring
195
+ * custom uniform variables, globals, and functions shared
196
+ * between hooks. To add declarations just in a vertex or fragment shader, add
197
+ * `vertexDeclarations` and `fragmentDeclarations` keys.
198
+ *
199
+ * @param The hooks in the shader to replace.
200
+ * @example <div modernizr='webgl'>
201
+ * <code>
202
+ * let myShader;
203
+ *
204
+ * function setup() {
205
+ * createCanvas(200, 200, WEBGL);
206
+ * myShader = baseMaterialShader().modify({
207
+ * uniforms: {
208
+ * 'float time': () => millis() // Uniform for time
209
+ * },
210
+ * 'Vertex getWorldInputs': `(Vertex inputs) {
211
+ * inputs.position.y +=
212
+ * 20. * sin(time * 0.001 + inputs.position.x * 0.05);
213
+ * return inputs;
214
+ * }`
215
+ * });
216
+ * }
217
+ *
218
+ * function draw() {
219
+ * background(255);
220
+ * shader(myShader); // Apply the custom shader
221
+ * lights(); // Enable lighting
222
+ * noStroke(); // Disable stroke
223
+ * fill('red'); // Set fill color to red
224
+ * sphere(50); // Draw a sphere with the shader applied
225
+ * }
226
+ * </code>
227
+ * </div>
228
+ * @example <div modernizr='webgl'>
229
+ * <code>
230
+ * let myShader;
231
+ *
232
+ * function setup() {
233
+ * createCanvas(200, 200, WEBGL);
234
+ * myShader = baseMaterialShader().modify({
235
+ * // Manually specifying a uniform
236
+ * declarations: 'uniform float time;',
237
+ * 'Vertex getWorldInputs': `(Vertex inputs) {
238
+ * inputs.position.y +=
239
+ * 20. * sin(time * 0.001 + inputs.position.x * 0.05);
240
+ * return inputs;
241
+ * }`
242
+ * });
243
+ * }
244
+ *
245
+ * function draw() {
246
+ * background(255);
247
+ * shader(myShader);
248
+ * myShader.setUniform('time', millis());
249
+ * lights();
250
+ * noStroke();
251
+ * fill('red');
252
+ * sphere(50);
253
+ * }
254
+ * </code>
255
+ * </div>
256
+ */
257
+ function modify(hooks?: object): p5.Shader;
258
+
259
+ /**
260
+ * Copies the shader from one drawing context to another.Each `p5.Shader` object must be compiled by calling
261
+ * shader() before it can run. Compilation happens
262
+ * in a drawing context which is usually the main canvas or an instance of
263
+ * p5.Graphics. A shader can only be used in the
264
+ * context where it was compiled. The `copyToContext()` method compiles the
265
+ * shader again and copies it to another drawing context where it can be
266
+ * reused.The parameter, `context`, is the drawing context where the shader will be
267
+ * used. The shader can be copied to an instance of
268
+ * p5.Graphics, as in
269
+ * `myShader.copyToContext(pg)`. The shader can also be copied from a
270
+ * p5.Graphics object to the main canvas using
271
+ * the `p5.instance` variable, as in `myShader.copyToContext(p5.instance)`.Note: A p5.Shader object created with
272
+ * createShader(),
273
+ * createFilterShader(), or
274
+ * loadShader()
275
+ * can be used directly with a p5.Framebuffer
276
+ * object created with
277
+ * createFramebuffer(). Both objects
278
+ * have the same context as the main canvas.
279
+ *
280
+ * @param WebGL context for the copied shader.
281
+ * @returns new shader compiled for the target context.
282
+ * @example <div>
283
+ * <code>
284
+ * // Note: A "uniform" is a global variable within a shader program.
285
+ *
286
+ * // Create a string with the vertex shader program.
287
+ * // The vertex shader is called for each vertex.
288
+ * let vertSrc = `
289
+ * precision highp float;
290
+ * uniform mat4 uModelViewMatrix;
291
+ * uniform mat4 uProjectionMatrix;
292
+ *
293
+ * attribute vec3 aPosition;
294
+ * attribute vec2 aTexCoord;
295
+ * varying vec2 vTexCoord;
296
+ *
297
+ * void main() {
298
+ * vTexCoord = aTexCoord;
299
+ * vec4 positionVec4 = vec4(aPosition, 1.0);
300
+ * gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;
301
+ * }
302
+ * `;
303
+ *
304
+ * // Create a string with the fragment shader program.
305
+ * // The fragment shader is called for each pixel.
306
+ * let fragSrc = `
307
+ * precision mediump float;
308
+ * varying vec2 vTexCoord;
309
+ *
310
+ * void main() {
311
+ * vec2 uv = vTexCoord;
312
+ * vec3 color = vec3(uv.x, uv.y, min(uv.x + uv.y, 1.0));
313
+ * gl_FragColor = vec4(color, 1.0);\
314
+ * }
315
+ * `;
316
+ *
317
+ * let pg;
318
+ *
319
+ * function setup() {
320
+ * createCanvas(100, 100, WEBGL);
321
+ *
322
+ * background(200);
323
+ *
324
+ * // Create a p5.Shader object.
325
+ * let original = createShader(vertSrc, fragSrc);
326
+ *
327
+ * // Compile the p5.Shader object.
328
+ * shader(original);
329
+ *
330
+ * // Create a p5.Graphics object.
331
+ * pg = createGraphics(50, 50, WEBGL);
332
+ *
333
+ * // Copy the original shader to the p5.Graphics object.
334
+ * let copied = original.copyToContext(pg);
335
+ *
336
+ * // Apply the copied shader to the p5.Graphics object.
337
+ * pg.shader(copied);
338
+ *
339
+ * // Style the display surface.
340
+ * pg.noStroke();
341
+ *
342
+ * // Add a display surface for the shader.
343
+ * pg.plane(50, 50);
344
+ *
345
+ * describe('A square with purple-blue gradient on its surface drawn against a gray background.');
346
+ * }
347
+ *
348
+ * function draw() {
349
+ * background(200);
350
+ *
351
+ * // Draw the p5.Graphics object to the main canvas.
352
+ * image(pg, -25, -25);
353
+ * }
354
+ * </code>
355
+ * </div>
356
+ *
357
+ * <div class='notest'>
358
+ * <code>
359
+ * // Note: A "uniform" is a global variable within a shader program.
360
+ *
361
+ * // Create a string with the vertex shader program.
362
+ * // The vertex shader is called for each vertex.
363
+ * let vertSrc = `
364
+ * precision highp float;
365
+ * uniform mat4 uModelViewMatrix;
366
+ * uniform mat4 uProjectionMatrix;
367
+ *
368
+ * attribute vec3 aPosition;
369
+ * attribute vec2 aTexCoord;
370
+ * varying vec2 vTexCoord;
371
+ *
372
+ * void main() {
373
+ * vTexCoord = aTexCoord;
374
+ * vec4 positionVec4 = vec4(aPosition, 1.0);
375
+ * gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;
376
+ * }
377
+ * `;
378
+ *
379
+ * // Create a string with the fragment shader program.
380
+ * // The fragment shader is called for each pixel.
381
+ * let fragSrc = `
382
+ * precision mediump float;
383
+ *
384
+ * varying vec2 vTexCoord;
385
+ *
386
+ * void main() {
387
+ * vec2 uv = vTexCoord;
388
+ * vec3 color = vec3(uv.x, uv.y, min(uv.x + uv.y, 1.0));
389
+ * gl_FragColor = vec4(color, 1.0);
390
+ * }
391
+ * `;
392
+ *
393
+ * let copied;
394
+ *
395
+ * function setup() {
396
+ * createCanvas(100, 100, WEBGL);
397
+ *
398
+ * // Create a p5.Graphics object.
399
+ * let pg = createGraphics(25, 25, WEBGL);
400
+ *
401
+ * // Create a p5.Shader object.
402
+ * let original = pg.createShader(vertSrc, fragSrc);
403
+ *
404
+ * // Compile the p5.Shader object.
405
+ * pg.shader(original);
406
+ *
407
+ * // Copy the original shader to the main canvas.
408
+ * copied = original.copyToContext(p5.instance);
409
+ *
410
+ * // Apply the copied shader to the main canvas.
411
+ * shader(copied);
412
+ *
413
+ * describe('A rotating cube with a purple-blue gradient on its surface drawn against a gray background.');
414
+ * }
415
+ *
416
+ * function draw() {
417
+ * background(200);
418
+ *
419
+ * // Rotate around the x-, y-, and z-axes.
420
+ * rotateX(frameCount * 0.01);
421
+ * rotateY(frameCount * 0.01);
422
+ * rotateZ(frameCount * 0.01);
423
+ *
424
+ * // Draw the box.
425
+ * box(50);
426
+ * }
427
+ * </code>
428
+ * </div>
429
+ */
430
+ function copyToContext(context: p5 | p5.Graphics): p5.Shader;
431
+
432
+ /**
433
+ * Sets the shader’s uniform (global) variables.Shader programs run on the computer’s graphics processing unit (GPU).
434
+ * They live in part of the computer’s memory that’s completely separate
435
+ * from the sketch that runs them. Uniforms are global variables within a
436
+ * shader program. They provide a way to pass values from a sketch running
437
+ * on the CPU to a shader program running on the GPU.The first parameter, `uniformName`, is a string with the uniform’s name.
438
+ * For the shader above, `uniformName` would be `'r'`.The second parameter, `data`, is the value that should be used to set the
439
+ * uniform. For example, calling `myShader.setUniform('r', 0.5)` would set
440
+ * the `r` uniform in the shader above to `0.5`. data should match the
441
+ * uniform’s type. Numbers, strings, booleans, arrays, and many types of
442
+ * images can all be passed to a shader with `setUniform()`.
443
+ *
444
+ * @param name of the uniform. Must match the name
445
+ * used in the vertex and fragment shaders.
446
+ * @param value to assign to the uniform. Must match the uniform’s data type.
447
+ * @example <div>
448
+ * <code>
449
+ * // Note: A "uniform" is a global variable within a shader program.
450
+ *
451
+ * // Create a string with the vertex shader program.
452
+ * // The vertex shader is called for each vertex.
453
+ * let vertSrc = `
454
+ * precision highp float;
455
+ * uniform mat4 uModelViewMatrix;
456
+ * uniform mat4 uProjectionMatrix;
457
+ *
458
+ * attribute vec3 aPosition;
459
+ * attribute vec2 aTexCoord;
460
+ * varying vec2 vTexCoord;
461
+ *
462
+ * void main() {
463
+ * vTexCoord = aTexCoord;
464
+ * vec4 positionVec4 = vec4(aPosition, 1.0);
465
+ * gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;
466
+ * }
467
+ * `;
468
+ *
469
+ * // Create a string with the fragment shader program.
470
+ * // The fragment shader is called for each pixel.
471
+ * let fragSrc = `
472
+ * precision mediump float;
473
+ *
474
+ * uniform float r;
475
+ *
476
+ * void main() {
477
+ * gl_FragColor = vec4(r, 1.0, 1.0, 1.0);
478
+ * }
479
+ * `;
480
+ *
481
+ * function setup() {
482
+ * createCanvas(100, 100, WEBGL);
483
+ *
484
+ * // Create a p5.Shader object.
485
+ * let myShader = createShader(vertSrc, fragSrc);
486
+ *
487
+ * // Apply the p5.Shader object.
488
+ * shader(myShader);
489
+ *
490
+ * // Set the r uniform to 0.5.
491
+ * myShader.setUniform('r', 0.5);
492
+ *
493
+ * // Style the drawing surface.
494
+ * noStroke();
495
+ *
496
+ * // Add a plane as a drawing surface for the shader.
497
+ * plane(100, 100);
498
+ *
499
+ * describe('A cyan square.');
500
+ * }
501
+ * </code>
502
+ * </div>
503
+ *
504
+ * <div>
505
+ * <code>
506
+ * // Note: A "uniform" is a global variable within a shader program.
507
+ *
508
+ * // Create a string with the vertex shader program.
509
+ * // The vertex shader is called for each vertex.
510
+ * let vertSrc = `
511
+ * precision highp float;
512
+ * uniform mat4 uModelViewMatrix;
513
+ * uniform mat4 uProjectionMatrix;
514
+ *
515
+ * attribute vec3 aPosition;
516
+ * attribute vec2 aTexCoord;
517
+ * varying vec2 vTexCoord;
518
+ *
519
+ * void main() {
520
+ * vTexCoord = aTexCoord;
521
+ * vec4 positionVec4 = vec4(aPosition, 1.0);
522
+ * gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;
523
+ * }
524
+ * `;
525
+ *
526
+ * // Create a string with the fragment shader program.
527
+ * // The fragment shader is called for each pixel.
528
+ * let fragSrc = `
529
+ * precision mediump float;
530
+ *
531
+ * uniform float r;
532
+ *
533
+ * void main() {
534
+ * gl_FragColor = vec4(r, 1.0, 1.0, 1.0);
535
+ * }
536
+ * `;
537
+ *
538
+ * let myShader;
539
+ *
540
+ * function setup() {
541
+ * createCanvas(100, 100, WEBGL);
542
+ *
543
+ * // Create a p5.Shader object.
544
+ * myShader = createShader(vertSrc, fragSrc);
545
+ *
546
+ * // Compile and apply the p5.Shader object.
547
+ * shader(myShader);
548
+ *
549
+ * describe('A square oscillates color between cyan and white.');
550
+ * }
551
+ *
552
+ * function draw() {
553
+ * background(200);
554
+ *
555
+ * // Style the drawing surface.
556
+ * noStroke();
557
+ *
558
+ * // Update the r uniform.
559
+ * let nextR = 0.5 * (sin(frameCount * 0.01) + 1);
560
+ * myShader.setUniform('r', nextR);
561
+ *
562
+ * // Add a plane as a drawing surface.
563
+ * plane(100, 100);
564
+ * }
565
+ * </code>
566
+ * </div>
567
+ *
568
+ * <div>
569
+ * <code>
570
+ * // Note: A "uniform" is a global variable within a shader program.
571
+ *
572
+ * // Create a string with the vertex shader program.
573
+ * // The vertex shader is called for each vertex.
574
+ * let vertSrc = `
575
+ * precision highp float;
576
+ * uniform mat4 uModelViewMatrix;
577
+ * uniform mat4 uProjectionMatrix;
578
+ *
579
+ * attribute vec3 aPosition;
580
+ * attribute vec2 aTexCoord;
581
+ * varying vec2 vTexCoord;
582
+ *
583
+ * void main() {
584
+ * vTexCoord = aTexCoord;
585
+ * vec4 positionVec4 = vec4(aPosition, 1.0);
586
+ * gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;
587
+ * }
588
+ * `;
589
+ *
590
+ * // Create a string with the fragment shader program.
591
+ * // The fragment shader is called for each pixel.
592
+ * let fragSrc = `
593
+ * precision highp float;
594
+ * uniform vec2 p;
595
+ * uniform float r;
596
+ * const int numIterations = 500;
597
+ * varying vec2 vTexCoord;
598
+ *
599
+ * void main() {
600
+ * vec2 c = p + gl_FragCoord.xy * r;
601
+ * vec2 z = c;
602
+ * float n = 0.0;
603
+ *
604
+ * for (int i = numIterations; i > 0; i--) {
605
+ * if (z.x * z.x + z.y * z.y > 4.0) {
606
+ * n = float(i) / float(numIterations);
607
+ * break;
608
+ * }
609
+ *
610
+ * z = vec2(z.x * z.x - z.y * z.y, 2.0 * z.x * z.y) + c;
611
+ * }
612
+ *
613
+ * gl_FragColor = vec4(
614
+ * 0.5 - cos(n * 17.0) / 2.0,
615
+ * 0.5 - cos(n * 13.0) / 2.0,
616
+ * 0.5 - cos(n * 23.0) / 2.0,
617
+ * 1.0
618
+ * );
619
+ * }
620
+ * `;
621
+ *
622
+ * let mandelbrot;
623
+ *
624
+ * function setup() {
625
+ * createCanvas(100, 100, WEBGL);
626
+ *
627
+ * // Create a p5.Shader object.
628
+ * mandelbrot = createShader(vertSrc, fragSrc);
629
+ *
630
+ * // Compile and apply the p5.Shader object.
631
+ * shader(mandelbrot);
632
+ *
633
+ * // Set the shader uniform p to an array.
634
+ * // p is the center point of the Mandelbrot image.
635
+ * mandelbrot.setUniform('p', [-0.74364388703, 0.13182590421]);
636
+ *
637
+ * describe('A fractal image zooms in and out of focus.');
638
+ * }
639
+ *
640
+ * function draw() {
641
+ * // Set the shader uniform r to a value that oscillates
642
+ * // between 0 and 0.005.
643
+ * // r is the size of the image in Mandelbrot-space.
644
+ * let radius = 0.005 * (sin(frameCount * 0.01) + 1);
645
+ * mandelbrot.setUniform('r', radius);
646
+ *
647
+ * // Style the drawing surface.
648
+ * noStroke();
649
+ *
650
+ * // Add a plane as a drawing surface.
651
+ * plane(100, 100);
652
+ * }
653
+ * </code>
654
+ * </div>
655
+ */
656
+ function setUniform(uniformName: string, data: boolean | number | number[] | p5.Image | p5.Graphics | p5.MediaElement | p5.Texture): void;
657
+
658
+ }
659
+
660
+ export default function p5_Shader(p5: any, fn: any): void;