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.
- package/dist/accessibility/color_namer.js +5 -5
- package/dist/accessibility/describe.js +10 -0
- package/dist/accessibility/index.js +5 -5
- package/dist/accessibility/outputs.js +21 -0
- package/dist/app.js +5 -5
- package/dist/color/color_conversion.js +5 -5
- package/dist/color/creating_reading.js +1 -1
- package/dist/color/index.js +2 -2
- package/dist/color/p5.Color.js +1 -1
- package/dist/color/setting.js +2 -2
- package/dist/{constants-C-g_eAdC.js → constants-BRcElHU3.js} +19 -3
- package/dist/core/constants.js +1 -1
- package/dist/core/environment.js +6 -5
- package/dist/core/friendly_errors/fes_core.js +1 -1
- package/dist/core/friendly_errors/index.js +1 -1
- package/dist/core/friendly_errors/param_validator.js +46 -93
- package/dist/core/friendly_errors/sketch_reader.js +5 -5
- package/dist/core/friendly_errors/sketch_verifier.js +1 -1
- package/dist/core/friendly_errors/validate_params.js +5 -5
- package/dist/core/helpers.js +1 -1
- package/dist/core/init.js +5 -5
- package/dist/core/legacy.js +5 -5
- package/dist/core/main.js +5 -5
- package/dist/core/p5.Graphics.js +4 -4
- package/dist/core/p5.Renderer.js +3 -3
- package/dist/core/p5.Renderer2D.js +5 -5
- package/dist/core/rendering.js +4 -4
- package/dist/{creating_reading-D4AAKRbx.js → creating_reading-Cr8L2Jnm.js} +2 -2
- package/dist/dom/dom.js +10 -10
- package/dist/dom/index.js +2 -2
- package/dist/dom/p5.Element.js +2 -2
- package/dist/dom/p5.MediaElement.js +2 -2
- package/dist/events/acceleration.js +24 -24
- package/dist/events/keyboard.js +11 -6
- package/dist/image/const.js +1 -1
- package/dist/image/filterRenderer2D.js +4 -4
- package/dist/image/image.js +4 -4
- package/dist/image/index.js +4 -4
- package/dist/image/loading_displaying.js +4 -4
- package/dist/image/p5.Image.js +3 -3
- package/dist/image/pixels.js +1 -0
- package/dist/io/files.js +4 -4
- package/dist/io/index.js +4 -4
- package/dist/io/p5.TableRow.js +2 -2
- package/dist/{main-s72KWcUy.js → main-BKN5yFoS.js} +12 -9
- package/dist/math/Matrices/Matrix.js +1 -1
- package/dist/math/Matrices/MatrixNumjs.js +1 -1
- package/dist/math/index.js +1 -1
- package/dist/math/math.js +1 -1
- package/dist/math/p5.Matrix.js +1 -1
- package/dist/math/p5.Vector.js +1 -1
- package/dist/math/trigonometry.js +1 -1
- package/dist/{p5.Renderer-CwAYZOC2.js → p5.Renderer-R23xoC7s.js} +5 -5
- package/dist/{rendering--aAe5aq3.js → rendering-CvUVN-Vb.js} +101 -66
- package/dist/shape/2d_primitives.js +1 -1
- package/dist/shape/attributes.js +1 -1
- package/dist/shape/custom_shapes.js +2 -2
- package/dist/shape/index.js +2 -2
- package/dist/type/index.js +3 -3
- package/dist/type/p5.Font.js +3 -5
- package/dist/type/textCore.js +4 -4
- package/dist/webgl/3d_primitives.js +4 -4
- package/dist/webgl/GeometryBuilder.js +1 -1
- package/dist/webgl/ShapeBuilder.js +1 -1
- package/dist/webgl/index.js +4 -4
- package/dist/webgl/interaction.js +1 -1
- package/dist/webgl/light.js +4 -4
- package/dist/webgl/loading.js +5 -4
- package/dist/webgl/material.js +4 -4
- package/dist/webgl/p5.Camera.js +4 -4
- package/dist/webgl/p5.Framebuffer.js +4 -4
- package/dist/webgl/p5.Geometry.js +1 -1
- package/dist/webgl/p5.Quat.js +1 -1
- package/dist/webgl/p5.RendererGL.js +4 -4
- package/dist/webgl/p5.Shader.js +4 -4
- package/dist/webgl/p5.Texture.js +4 -4
- package/dist/webgl/text.js +32 -34
- package/lib/p5.esm.js +289 -247
- package/lib/p5.js +289 -247
- package/lib/p5.min.js +1 -1
- package/package.json +1 -2
- package/types/accessibility/color_namer.d.ts +8 -0
- package/types/accessibility/describe.d.ts +184 -0
- package/types/accessibility/gridOutput.d.ts +8 -0
- package/types/accessibility/outputs.d.ts +235 -0
- package/types/accessibility/textOutput.d.ts +8 -0
- package/types/color/color_conversion.d.ts +47 -0
- package/types/color/creating_reading.d.ts +1348 -0
- package/types/color/p5.Color.d.ts +1070 -0
- package/types/color/setting.d.ts +2085 -0
- package/types/core/constants.d.ts +341 -0
- package/types/core/environment.d.ts +668 -0
- package/types/core/friendly_errors/fes_core.d.ts +8 -0
- package/types/core/friendly_errors/file_errors.d.ts +8 -0
- package/types/core/friendly_errors/param_validator.d.ts +30 -0
- package/types/core/friendly_errors/sketch_reader.d.ts +8 -0
- package/types/core/friendly_errors/stacktrace.d.ts +11 -0
- package/types/core/friendly_errors/validate_params.d.ts +8 -0
- package/types/core/helpers.d.ts +8 -0
- package/types/core/legacy.d.ts +8 -0
- package/types/core/main.d.ts +5999 -0
- package/types/core/p5.Graphics.d.ts +484 -0
- package/types/core/p5.Renderer.d.ts +14 -0
- package/types/core/reference.d.ts +8 -0
- package/types/core/rendering.d.ts +481 -0
- package/types/core/structure.d.ts +492 -0
- package/types/core/transform.d.ts +1638 -0
- package/types/data/local_storage.d.ts +323 -0
- package/types/dom/dom.d.ts +1295 -0
- package/types/dom/p5.Element.d.ts +2011 -0
- package/types/dom/p5.File.d.ts +13 -0
- package/types/dom/p5.MediaElement.d.ts +1249 -0
- package/types/events/acceleration.d.ts +193 -0
- package/types/events/keyboard.d.ts +501 -0
- package/types/events/pointer.d.ts +782 -0
- package/types/global.d.ts +5544 -0
- package/types/image/filterRenderer2D.d.ts +54 -0
- package/types/image/image.d.ts +326 -0
- package/types/image/loading_displaying.d.ts +580 -0
- package/types/image/p5.Image.d.ts +5882 -0
- package/types/image/pixels.d.ts +832 -0
- package/types/io/files.d.ts +1447 -0
- package/types/io/p5.Table.d.ts +1247 -0
- package/types/io/p5.TableRow.d.ts +343 -0
- package/types/io/p5.XML.d.ts +1188 -0
- package/types/math/Matrices/Matrix.d.ts +1029 -0
- package/types/math/Matrices/MatrixNumjs.d.ts +8 -0
- package/types/math/calculation.d.ts +923 -0
- package/types/math/math.d.ts +90 -0
- package/types/math/noise.d.ts +311 -0
- package/types/math/p5.Matrix.d.ts +8 -0
- package/types/math/p5.Vector.d.ts +3416 -0
- package/types/math/random.d.ts +267 -0
- package/types/math/trigonometry.d.ts +663 -0
- package/types/p5.d.ts +6666 -0
- package/types/shape/2d_primitives.d.ts +1033 -0
- package/types/shape/attributes.d.ts +466 -0
- package/types/shape/curves.d.ts +740 -0
- package/types/shape/custom_shapes.d.ts +888 -0
- package/types/shape/vertex.d.ts +1141 -0
- package/types/type/p5.Font.d.ts +575 -0
- package/types/type/textCore.d.ts +1198 -0
- package/types/utilities/conversion.d.ts +894 -0
- package/types/utilities/time_date.d.ts +295 -0
- package/types/utilities/utility_functions.d.ts +587 -0
- package/types/webgl/3d_primitives.d.ts +1432 -0
- package/types/webgl/ShaderGenerator.d.ts +8 -0
- package/types/webgl/interaction.d.ts +371 -0
- package/types/webgl/light.d.ts +1184 -0
- package/types/webgl/loading.d.ts +482 -0
- package/types/webgl/material.d.ts +2656 -0
- package/types/webgl/p5.Camera.d.ts +3023 -0
- package/types/webgl/p5.DataArray.d.ts +61 -0
- package/types/webgl/p5.Framebuffer.d.ts +760 -0
- package/types/webgl/p5.Geometry.d.ts +1191 -0
- package/types/webgl/p5.Quat.d.ts +45 -0
- package/types/webgl/p5.RendererGL.d.ts +234 -0
- package/types/webgl/p5.Shader.d.ts +660 -0
- package/types/webgl/p5.Texture.d.ts +61 -0
- package/types/webgl/text.d.ts +74 -0
|
@@ -0,0 +1,1141 @@
|
|
|
1
|
+
// This file is auto-generated from JSDoc documentation
|
|
2
|
+
|
|
3
|
+
import p5 from 'p5';
|
|
4
|
+
import { Color } from '../color/p5.Color';
|
|
5
|
+
import { Vector } from '../math/p5.Vector';
|
|
6
|
+
|
|
7
|
+
declare module 'p5' {
|
|
8
|
+
/**
|
|
9
|
+
* Begins adding vertices to a custom shape.The `beginShape()` and endShape() functions
|
|
10
|
+
* allow for creating custom shapes in 2D or 3D. `beginShape()` begins adding
|
|
11
|
+
* vertices to a custom shape and endShape() stops
|
|
12
|
+
* adding them.The parameter, `kind`, sets the kind of shape to make. The available kinds are:After calling `beginShape()`, shapes can be built by calling
|
|
13
|
+
* vertex(),
|
|
14
|
+
* bezierVertex(), and/or
|
|
15
|
+
* splineVertex(). Calling
|
|
16
|
+
* endShape() will stop adding vertices to the
|
|
17
|
+
* shape. Each shape will be outlined with the current stroke color and filled
|
|
18
|
+
* with the current fill color.Transformations such as translate(),
|
|
19
|
+
* rotate(), and
|
|
20
|
+
* scale() don't work between `beginShape()` and
|
|
21
|
+
* endShape(). It's also not possible to use
|
|
22
|
+
* other shapes, such as ellipse() or
|
|
23
|
+
* rect(), between `beginShape()` and
|
|
24
|
+
* endShape().
|
|
25
|
+
*
|
|
26
|
+
* @param either POINTS, LINES, TRIANGLES, TRIANGLE_FAN
|
|
27
|
+
* TRIANGLE_STRIP, QUADS, QUAD_STRIP or PATH. Defaults to PATH.
|
|
28
|
+
* @example <div>
|
|
29
|
+
* <code>
|
|
30
|
+
* function setup() {
|
|
31
|
+
* createCanvas(100, 100);
|
|
32
|
+
*
|
|
33
|
+
* background(200);
|
|
34
|
+
*
|
|
35
|
+
* // Start drawing the shape.
|
|
36
|
+
* beginShape();
|
|
37
|
+
*
|
|
38
|
+
* // Add vertices.
|
|
39
|
+
* vertex(30, 20);
|
|
40
|
+
* vertex(85, 20);
|
|
41
|
+
* vertex(85, 75);
|
|
42
|
+
* vertex(30, 75);
|
|
43
|
+
*
|
|
44
|
+
* // Stop drawing the shape.
|
|
45
|
+
* endShape(CLOSE);
|
|
46
|
+
*
|
|
47
|
+
* describe('A white square on a gray background.');
|
|
48
|
+
* }
|
|
49
|
+
* </code>
|
|
50
|
+
* </div>
|
|
51
|
+
*
|
|
52
|
+
* <div>
|
|
53
|
+
* <code>
|
|
54
|
+
* function setup() {
|
|
55
|
+
* createCanvas(100, 100);
|
|
56
|
+
*
|
|
57
|
+
* background(200);
|
|
58
|
+
*
|
|
59
|
+
* // Start drawing the shape.
|
|
60
|
+
* // Only draw the vertices (points).
|
|
61
|
+
* beginShape(POINTS);
|
|
62
|
+
*
|
|
63
|
+
* // Add vertices.
|
|
64
|
+
* vertex(30, 20);
|
|
65
|
+
* vertex(85, 20);
|
|
66
|
+
* vertex(85, 75);
|
|
67
|
+
* vertex(30, 75);
|
|
68
|
+
*
|
|
69
|
+
* // Stop drawing the shape.
|
|
70
|
+
* endShape();
|
|
71
|
+
*
|
|
72
|
+
* describe('Four black dots that form a square are drawn on a gray background.');
|
|
73
|
+
* }
|
|
74
|
+
* </code>
|
|
75
|
+
* </div>
|
|
76
|
+
*
|
|
77
|
+
* <div>
|
|
78
|
+
* <code>
|
|
79
|
+
* function setup() {
|
|
80
|
+
* createCanvas(100, 100);
|
|
81
|
+
*
|
|
82
|
+
* background(200);
|
|
83
|
+
*
|
|
84
|
+
* // Start drawing the shape.
|
|
85
|
+
* // Only draw lines between alternating pairs of vertices.
|
|
86
|
+
* beginShape(LINES);
|
|
87
|
+
*
|
|
88
|
+
* // Add vertices.
|
|
89
|
+
* vertex(30, 20);
|
|
90
|
+
* vertex(85, 20);
|
|
91
|
+
* vertex(85, 75);
|
|
92
|
+
* vertex(30, 75);
|
|
93
|
+
*
|
|
94
|
+
* // Stop drawing the shape.
|
|
95
|
+
* endShape();
|
|
96
|
+
*
|
|
97
|
+
* describe('Two horizontal black lines on a gray background.');
|
|
98
|
+
* }
|
|
99
|
+
* </code>
|
|
100
|
+
* </div>
|
|
101
|
+
*
|
|
102
|
+
* <div>
|
|
103
|
+
* <code>
|
|
104
|
+
* function setup() {
|
|
105
|
+
* createCanvas(100, 100);
|
|
106
|
+
*
|
|
107
|
+
* background(200);
|
|
108
|
+
*
|
|
109
|
+
* // Style the shape.
|
|
110
|
+
* noFill();
|
|
111
|
+
*
|
|
112
|
+
* // Start drawing the shape.
|
|
113
|
+
* beginShape();
|
|
114
|
+
*
|
|
115
|
+
* // Add vertices.
|
|
116
|
+
* vertex(30, 20);
|
|
117
|
+
* vertex(85, 20);
|
|
118
|
+
* vertex(85, 75);
|
|
119
|
+
* vertex(30, 75);
|
|
120
|
+
*
|
|
121
|
+
* // Stop drawing the shape.
|
|
122
|
+
* endShape();
|
|
123
|
+
*
|
|
124
|
+
* describe('Three black lines form a sideways U shape on a gray background.');
|
|
125
|
+
* }
|
|
126
|
+
* </code>
|
|
127
|
+
* </div>
|
|
128
|
+
*
|
|
129
|
+
* <div>
|
|
130
|
+
* <code>
|
|
131
|
+
* function setup() {
|
|
132
|
+
* createCanvas(100, 100);
|
|
133
|
+
*
|
|
134
|
+
* background(200);
|
|
135
|
+
*
|
|
136
|
+
* // Style the shape.
|
|
137
|
+
* noFill();
|
|
138
|
+
*
|
|
139
|
+
* // Start drawing the shape.
|
|
140
|
+
* beginShape();
|
|
141
|
+
*
|
|
142
|
+
* // Add vertices.
|
|
143
|
+
* vertex(30, 20);
|
|
144
|
+
* vertex(85, 20);
|
|
145
|
+
* vertex(85, 75);
|
|
146
|
+
* vertex(30, 75);
|
|
147
|
+
*
|
|
148
|
+
* // Stop drawing the shape.
|
|
149
|
+
* // Connect the first and last vertices.
|
|
150
|
+
* endShape(CLOSE);
|
|
151
|
+
*
|
|
152
|
+
* describe('A black outline of a square drawn on a gray background.');
|
|
153
|
+
* }
|
|
154
|
+
* </code>
|
|
155
|
+
* </div>
|
|
156
|
+
*
|
|
157
|
+
* <div>
|
|
158
|
+
* <code>
|
|
159
|
+
* function setup() {
|
|
160
|
+
* createCanvas(100, 100);
|
|
161
|
+
*
|
|
162
|
+
* background(200);
|
|
163
|
+
*
|
|
164
|
+
* // Start drawing the shape.
|
|
165
|
+
* // Draw a series of triangles.
|
|
166
|
+
* beginShape(TRIANGLES);
|
|
167
|
+
*
|
|
168
|
+
* // Left triangle.
|
|
169
|
+
* vertex(30, 75);
|
|
170
|
+
* vertex(40, 20);
|
|
171
|
+
* vertex(50, 75);
|
|
172
|
+
*
|
|
173
|
+
* // Right triangle.
|
|
174
|
+
* vertex(60, 20);
|
|
175
|
+
* vertex(70, 75);
|
|
176
|
+
* vertex(80, 20);
|
|
177
|
+
*
|
|
178
|
+
* // Stop drawing the shape.
|
|
179
|
+
* endShape();
|
|
180
|
+
*
|
|
181
|
+
* describe('Two white triangles drawn on a gray background.');
|
|
182
|
+
* }
|
|
183
|
+
* </code>
|
|
184
|
+
* </div>
|
|
185
|
+
*
|
|
186
|
+
* <div>
|
|
187
|
+
* <code>
|
|
188
|
+
* function setup() {
|
|
189
|
+
* createCanvas(100, 100);
|
|
190
|
+
*
|
|
191
|
+
* background(200);
|
|
192
|
+
*
|
|
193
|
+
* // Start drawing the shape.
|
|
194
|
+
* // Draw a series of triangles.
|
|
195
|
+
* beginShape(TRIANGLE_STRIP);
|
|
196
|
+
*
|
|
197
|
+
* // Add vertices.
|
|
198
|
+
* vertex(30, 75);
|
|
199
|
+
* vertex(40, 20);
|
|
200
|
+
* vertex(50, 75);
|
|
201
|
+
* vertex(60, 20);
|
|
202
|
+
* vertex(70, 75);
|
|
203
|
+
* vertex(80, 20);
|
|
204
|
+
* vertex(90, 75);
|
|
205
|
+
*
|
|
206
|
+
* // Stop drawing the shape.
|
|
207
|
+
* endShape();
|
|
208
|
+
*
|
|
209
|
+
* describe('Five white triangles that are interleaved drawn on a gray background.');
|
|
210
|
+
* }
|
|
211
|
+
* </code>
|
|
212
|
+
* </div>
|
|
213
|
+
*
|
|
214
|
+
* <div>
|
|
215
|
+
* <code>
|
|
216
|
+
* function setup() {
|
|
217
|
+
* createCanvas(100, 100);
|
|
218
|
+
*
|
|
219
|
+
* background(200);
|
|
220
|
+
*
|
|
221
|
+
* // Start drawing the shape.
|
|
222
|
+
* // Draw a series of triangles that share their first vertex.
|
|
223
|
+
* beginShape(TRIANGLE_FAN);
|
|
224
|
+
*
|
|
225
|
+
* // Add vertices.
|
|
226
|
+
* vertex(57.5, 50);
|
|
227
|
+
* vertex(57.5, 15);
|
|
228
|
+
* vertex(92, 50);
|
|
229
|
+
* vertex(57.5, 85);
|
|
230
|
+
* vertex(22, 50);
|
|
231
|
+
* vertex(57.5, 15);
|
|
232
|
+
*
|
|
233
|
+
* // Stop drawing the shape.
|
|
234
|
+
* endShape();
|
|
235
|
+
*
|
|
236
|
+
* describe('Four white triangles form a square are drawn on a gray background.');
|
|
237
|
+
* }
|
|
238
|
+
* </code>
|
|
239
|
+
* </div>
|
|
240
|
+
*
|
|
241
|
+
* <div>
|
|
242
|
+
* <code>
|
|
243
|
+
* function setup() {
|
|
244
|
+
* createCanvas(100, 100);
|
|
245
|
+
*
|
|
246
|
+
* background(200);
|
|
247
|
+
*
|
|
248
|
+
* // Start drawing the shape.
|
|
249
|
+
* // Draw a series of quadrilaterals.
|
|
250
|
+
* beginShape(QUADS);
|
|
251
|
+
*
|
|
252
|
+
* // Left rectangle.
|
|
253
|
+
* vertex(30, 20);
|
|
254
|
+
* vertex(30, 75);
|
|
255
|
+
* vertex(50, 75);
|
|
256
|
+
* vertex(50, 20);
|
|
257
|
+
*
|
|
258
|
+
* // Right rectangle.
|
|
259
|
+
* vertex(65, 20);
|
|
260
|
+
* vertex(65, 75);
|
|
261
|
+
* vertex(85, 75);
|
|
262
|
+
* vertex(85, 20);
|
|
263
|
+
*
|
|
264
|
+
* // Stop drawing the shape.
|
|
265
|
+
* endShape();
|
|
266
|
+
*
|
|
267
|
+
* describe('Two white rectangles drawn on a gray background.');
|
|
268
|
+
* }
|
|
269
|
+
* </code>
|
|
270
|
+
* </div>
|
|
271
|
+
*
|
|
272
|
+
* <div>
|
|
273
|
+
* <code>
|
|
274
|
+
* function setup() {
|
|
275
|
+
* createCanvas(100, 100);
|
|
276
|
+
*
|
|
277
|
+
* background(200);
|
|
278
|
+
*
|
|
279
|
+
* // Start drawing the shape.
|
|
280
|
+
* // Draw a series of quadrilaterals.
|
|
281
|
+
* beginShape(QUAD_STRIP);
|
|
282
|
+
*
|
|
283
|
+
* // Add vertices.
|
|
284
|
+
* vertex(30, 20);
|
|
285
|
+
* vertex(30, 75);
|
|
286
|
+
* vertex(50, 20);
|
|
287
|
+
* vertex(50, 75);
|
|
288
|
+
* vertex(65, 20);
|
|
289
|
+
* vertex(65, 75);
|
|
290
|
+
* vertex(85, 20);
|
|
291
|
+
* vertex(85, 75);
|
|
292
|
+
*
|
|
293
|
+
* // Stop drawing the shape.
|
|
294
|
+
* endShape();
|
|
295
|
+
*
|
|
296
|
+
* describe('Three white rectangles that share edges are drawn on a gray background.');
|
|
297
|
+
* }
|
|
298
|
+
* </code>
|
|
299
|
+
* </div>
|
|
300
|
+
*
|
|
301
|
+
* <div>
|
|
302
|
+
* <code>
|
|
303
|
+
* function setup() {
|
|
304
|
+
* createCanvas(100, 100, WEBGL);
|
|
305
|
+
*
|
|
306
|
+
* background(200);
|
|
307
|
+
*
|
|
308
|
+
* // Start drawing the shape.
|
|
309
|
+
* // Draw a series of quadrilaterals.
|
|
310
|
+
* beginShape(PATH);
|
|
311
|
+
*
|
|
312
|
+
* // Add the vertices.
|
|
313
|
+
* vertex(-30, -30, 0);
|
|
314
|
+
* vertex(30, -30, 0);
|
|
315
|
+
* vertex(30, -10, 0);
|
|
316
|
+
* vertex(-10, -10, 0);
|
|
317
|
+
* vertex(-10, 10, 0);
|
|
318
|
+
* vertex(30, 10, 0);
|
|
319
|
+
* vertex(30, 30, 0);
|
|
320
|
+
* vertex(-30, 30, 0);
|
|
321
|
+
*
|
|
322
|
+
* // Stop drawing the shape.
|
|
323
|
+
* // Connect the first and last vertices.
|
|
324
|
+
* endShape(CLOSE);
|
|
325
|
+
*
|
|
326
|
+
* describe('A blocky C shape drawn in white on a gray background.');
|
|
327
|
+
* }
|
|
328
|
+
* </code>
|
|
329
|
+
* </div>
|
|
330
|
+
*
|
|
331
|
+
* <div>
|
|
332
|
+
* <code>
|
|
333
|
+
* // Click and drag with the mouse to view the scene from different angles.
|
|
334
|
+
*
|
|
335
|
+
* function setup() {
|
|
336
|
+
* createCanvas(100, 100, WEBGL);
|
|
337
|
+
*
|
|
338
|
+
* describe('A blocky C shape drawn in red, blue, and green on a gray background.');
|
|
339
|
+
* }
|
|
340
|
+
*
|
|
341
|
+
* function draw() {
|
|
342
|
+
* background(200);
|
|
343
|
+
*
|
|
344
|
+
* // Enable orbiting with the mouse.
|
|
345
|
+
* orbitControl();
|
|
346
|
+
*
|
|
347
|
+
* // Start drawing the shape.
|
|
348
|
+
* // Draw a series of quadrilaterals.
|
|
349
|
+
* beginShape(PATH);
|
|
350
|
+
*
|
|
351
|
+
* // Add the vertices.
|
|
352
|
+
* fill('red');
|
|
353
|
+
* stroke('red');
|
|
354
|
+
* vertex(-30, -30, 0);
|
|
355
|
+
* vertex(30, -30, 0);
|
|
356
|
+
* vertex(30, -10, 0);
|
|
357
|
+
* fill('green');
|
|
358
|
+
* stroke('green');
|
|
359
|
+
* vertex(-10, -10, 0);
|
|
360
|
+
* vertex(-10, 10, 0);
|
|
361
|
+
* vertex(30, 10, 0);
|
|
362
|
+
* fill('blue');
|
|
363
|
+
* stroke('blue');
|
|
364
|
+
* vertex(30, 30, 0);
|
|
365
|
+
* vertex(-30, 30, 0);
|
|
366
|
+
*
|
|
367
|
+
* // Stop drawing the shape.
|
|
368
|
+
* // Connect the first and last vertices.
|
|
369
|
+
* endShape(CLOSE);
|
|
370
|
+
* }
|
|
371
|
+
* </code>
|
|
372
|
+
* </div>
|
|
373
|
+
*/
|
|
374
|
+
function beginShape(kind: POINTS | LINES | TRIANGLES | TRIANGLE_FAN | TRIANGLE_STRIP | QUADS | QUAD_STRIP | PATH): void;
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Adds a Bézier curve segment to a custom shape.`bezierVertex()` adds a curved segment to custom shapes. The Bézier curves
|
|
378
|
+
* it creates are defined like those made by the
|
|
379
|
+
* bezier() function. `bezierVertex()` must be
|
|
380
|
+
* called between the
|
|
381
|
+
* beginShape() and
|
|
382
|
+
* endShape() functions.
|
|
383
|
+
* Bézier need a starting point. Building a shape
|
|
384
|
+
* only with Bézier curves needs one initial
|
|
385
|
+
* call to bezierVertex(), before
|
|
386
|
+
* a number of `bezierVertex()` calls that is a multiple of the parameter
|
|
387
|
+
* set by bezierOrder(...) (default 3).
|
|
388
|
+
* But shapes can mix different types of vertices, so if there
|
|
389
|
+
* are some previous vertices, then the initial anchor is not needed,
|
|
390
|
+
* only the multiples of 3 (or the Bézier order) calls to
|
|
391
|
+
* `bezierVertex` for each curve.Each curve of order 3 requires three calls to `bezierVertex`, so
|
|
392
|
+
* 2 curves would need 7 calls to `bezierVertex()`:
|
|
393
|
+
* (1 one initial anchor point, two sets of 3 curves describing the curves)
|
|
394
|
+
* With `bezierOrder(2)`, two curves would need 5 calls: 1 + 2 + 2.Bézier curves can also be drawn in 3D using WebGL mode.Note: `bezierVertex()` won’t work when an argument is passed to
|
|
395
|
+
* beginShape().
|
|
396
|
+
*
|
|
397
|
+
* @param x-coordinate of the first control point.
|
|
398
|
+
* @param y-coordinate of the first control point.
|
|
399
|
+
* @example <div>
|
|
400
|
+
* <code>
|
|
401
|
+
* function setup() {
|
|
402
|
+
* createCanvas(100, 100);
|
|
403
|
+
*
|
|
404
|
+
* background(200);
|
|
405
|
+
*
|
|
406
|
+
* // Style the shape.
|
|
407
|
+
* noFill();
|
|
408
|
+
*
|
|
409
|
+
* // Start drawing the shape.
|
|
410
|
+
* beginShape();
|
|
411
|
+
*
|
|
412
|
+
* // Add the first anchor point.
|
|
413
|
+
* bezierVertex(30, 20);
|
|
414
|
+
*
|
|
415
|
+
* // Add the Bézier vertex.
|
|
416
|
+
* bezierVertex(80, 0);
|
|
417
|
+
* bezierVertex(80, 75);
|
|
418
|
+
* bezierVertex(30, 75);
|
|
419
|
+
*
|
|
420
|
+
* // Stop drawing the shape.
|
|
421
|
+
* endShape();
|
|
422
|
+
*
|
|
423
|
+
* describe('A black C curve on a gray background.');
|
|
424
|
+
* }
|
|
425
|
+
* </code>
|
|
426
|
+
* </div>
|
|
427
|
+
*
|
|
428
|
+
* <div>
|
|
429
|
+
* <code>
|
|
430
|
+
* function setup() {
|
|
431
|
+
* createCanvas(100, 100);
|
|
432
|
+
*
|
|
433
|
+
* background(200);
|
|
434
|
+
*
|
|
435
|
+
* // Draw the anchor points in black.
|
|
436
|
+
* stroke(0);
|
|
437
|
+
* strokeWeight(5);
|
|
438
|
+
* point(30, 20);
|
|
439
|
+
* point(30, 75);
|
|
440
|
+
*
|
|
441
|
+
* // Draw the control points in red.
|
|
442
|
+
* stroke(255, 0, 0);
|
|
443
|
+
* point(80, 0);
|
|
444
|
+
* point(80, 75);
|
|
445
|
+
*
|
|
446
|
+
* // Style the shape.
|
|
447
|
+
* noFill();
|
|
448
|
+
* stroke(0);
|
|
449
|
+
* strokeWeight(1);
|
|
450
|
+
*
|
|
451
|
+
* // Start drawing the shape.
|
|
452
|
+
* beginShape();
|
|
453
|
+
*
|
|
454
|
+
* // Add the first anchor point.
|
|
455
|
+
* bezierVertex(30, 20);
|
|
456
|
+
*
|
|
457
|
+
* // Add the Bézier vertex.
|
|
458
|
+
* bezierVertex(80, 0);
|
|
459
|
+
* bezierVertex(80, 75);
|
|
460
|
+
* bezierVertex(30, 75);
|
|
461
|
+
*
|
|
462
|
+
* // Stop drawing the shape.
|
|
463
|
+
* endShape();
|
|
464
|
+
*
|
|
465
|
+
* // Draw red lines from the anchor points to the control points.
|
|
466
|
+
* stroke(255, 0, 0);
|
|
467
|
+
* line(30, 20, 80, 0);
|
|
468
|
+
* line(30, 75, 80, 75);
|
|
469
|
+
*
|
|
470
|
+
* describe(
|
|
471
|
+
* 'A gray square with three curves. A black curve has two straight, red lines that extend from its ends. The endpoints of all the curves are marked with dots.'
|
|
472
|
+
* );
|
|
473
|
+
* }
|
|
474
|
+
* </code>
|
|
475
|
+
* </div>
|
|
476
|
+
*
|
|
477
|
+
* <div>
|
|
478
|
+
* <code>
|
|
479
|
+
* // Click the mouse near the red dot in the top-right corner
|
|
480
|
+
* // and drag to change the curve's shape.
|
|
481
|
+
*
|
|
482
|
+
* let x2 = 80;
|
|
483
|
+
* let y2 = 0;
|
|
484
|
+
* let isChanging = false;
|
|
485
|
+
*
|
|
486
|
+
* function setup() {
|
|
487
|
+
* createCanvas(100, 100);
|
|
488
|
+
*
|
|
489
|
+
* describe(
|
|
490
|
+
* 'A gray square with three curves. A black curve has two straight, red lines that extend from its ends. The endpoints of all the curves are marked with dots.'
|
|
491
|
+
* );
|
|
492
|
+
* }
|
|
493
|
+
*
|
|
494
|
+
* function draw() {
|
|
495
|
+
* background(200);
|
|
496
|
+
*
|
|
497
|
+
* // Draw the anchor points in black.
|
|
498
|
+
* stroke(0);
|
|
499
|
+
* strokeWeight(5);
|
|
500
|
+
* point(30, 20);
|
|
501
|
+
* point(30, 75);
|
|
502
|
+
*
|
|
503
|
+
* // Draw the control points in red.
|
|
504
|
+
* stroke(255, 0, 0);
|
|
505
|
+
* point(x2, y2);
|
|
506
|
+
* point(80, 75);
|
|
507
|
+
*
|
|
508
|
+
* // Style the shape.
|
|
509
|
+
* noFill();
|
|
510
|
+
* stroke(0);
|
|
511
|
+
* strokeWeight(1);
|
|
512
|
+
*
|
|
513
|
+
* // Start drawing the shape.
|
|
514
|
+
* beginShape();
|
|
515
|
+
*
|
|
516
|
+
* // Add the first anchor point.
|
|
517
|
+
* bezierVertex(30, 20);
|
|
518
|
+
*
|
|
519
|
+
* // Add the Bézier vertex.
|
|
520
|
+
* bezierVertex(x2, y2);
|
|
521
|
+
* bezierVertex(80, 75);
|
|
522
|
+
* bezierVertex(30, 75);
|
|
523
|
+
*
|
|
524
|
+
* // Stop drawing the shape.
|
|
525
|
+
* endShape();
|
|
526
|
+
*
|
|
527
|
+
* // Draw red lines from the anchor points to the control points.
|
|
528
|
+
* stroke(255, 0, 0);
|
|
529
|
+
* line(30, 20, x2, y2);
|
|
530
|
+
* line(30, 75, 80, 75);
|
|
531
|
+
* }
|
|
532
|
+
*
|
|
533
|
+
* // Start changing the first control point if the user clicks near it.
|
|
534
|
+
* function mousePressed() {
|
|
535
|
+
* if (dist(mouseX, mouseY, x2, y2) < 20) {
|
|
536
|
+
* isChanging = true;
|
|
537
|
+
* }
|
|
538
|
+
* }
|
|
539
|
+
*
|
|
540
|
+
* // Stop changing the first control point when the user releases the mouse.
|
|
541
|
+
* function mouseReleased() {
|
|
542
|
+
* isChanging = false;
|
|
543
|
+
* }
|
|
544
|
+
*
|
|
545
|
+
* // Update the first control point while the user drags the mouse.
|
|
546
|
+
* function mouseDragged() {
|
|
547
|
+
* if (isChanging === true) {
|
|
548
|
+
* x2 = mouseX;
|
|
549
|
+
* y2 = mouseY;
|
|
550
|
+
* }
|
|
551
|
+
* }
|
|
552
|
+
* </code>
|
|
553
|
+
* </div>
|
|
554
|
+
*
|
|
555
|
+
* <div>
|
|
556
|
+
* <code>
|
|
557
|
+
* function setup() {
|
|
558
|
+
* createCanvas(100, 100);
|
|
559
|
+
*
|
|
560
|
+
* background(200);
|
|
561
|
+
*
|
|
562
|
+
* // Start drawing the shape.
|
|
563
|
+
* beginShape();
|
|
564
|
+
*
|
|
565
|
+
* // Add the first anchor point.
|
|
566
|
+
* bezierVertex(30, 20);
|
|
567
|
+
*
|
|
568
|
+
* // Add the Bézier vertices.
|
|
569
|
+
* bezierVertex(80, 0);
|
|
570
|
+
* bezierVertex(80, 75);
|
|
571
|
+
* bezierVertex(30, 75);
|
|
572
|
+
*
|
|
573
|
+
* bezierVertex(50, 80);
|
|
574
|
+
* bezierVertex(60, 25);
|
|
575
|
+
* bezierVertex(30, 20);
|
|
576
|
+
*
|
|
577
|
+
* // Stop drawing the shape.
|
|
578
|
+
* endShape();
|
|
579
|
+
*
|
|
580
|
+
* describe('A crescent moon shape drawn in white on a gray background.');
|
|
581
|
+
* }
|
|
582
|
+
* </code>
|
|
583
|
+
* </div>
|
|
584
|
+
*
|
|
585
|
+
* <div>
|
|
586
|
+
* <code>
|
|
587
|
+
* // Click and drag the mouse to view the scene from different angles.
|
|
588
|
+
*
|
|
589
|
+
* function setup() {
|
|
590
|
+
* createCanvas(100, 100, WEBGL);
|
|
591
|
+
*
|
|
592
|
+
* describe('A crescent moon shape drawn in white on a blue background. When the user drags the mouse, the scene rotates and a second moon is revealed.');
|
|
593
|
+
* }
|
|
594
|
+
*
|
|
595
|
+
* function draw() {
|
|
596
|
+
* background('midnightblue');
|
|
597
|
+
*
|
|
598
|
+
* // Enable orbiting with the mouse.
|
|
599
|
+
* orbitControl();
|
|
600
|
+
*
|
|
601
|
+
* // Style the moons.
|
|
602
|
+
* noStroke();
|
|
603
|
+
* fill('lemonchiffon');
|
|
604
|
+
*
|
|
605
|
+
* // Draw the first moon.
|
|
606
|
+
* beginShape();
|
|
607
|
+
* bezierVertex(-20, -30, 0);
|
|
608
|
+
*
|
|
609
|
+
* bezierVertex(30, -50, 0);
|
|
610
|
+
* bezierVertex(30, 25, 0);
|
|
611
|
+
* bezierVertex(-20, 25, 0);
|
|
612
|
+
*
|
|
613
|
+
* bezierVertex(0, 30, 0);
|
|
614
|
+
* bezierVertex(10, -25, 0);
|
|
615
|
+
* bezierVertex(-20, -30, 0);
|
|
616
|
+
* endShape();
|
|
617
|
+
*
|
|
618
|
+
* // Draw the second moon.
|
|
619
|
+
* beginShape();
|
|
620
|
+
*
|
|
621
|
+
* bezierVertex(-20, -30, -20);
|
|
622
|
+
*
|
|
623
|
+
* bezierVertex(30, -50, -20);
|
|
624
|
+
* bezierVertex(30, 25, -20);
|
|
625
|
+
* bezierVertex(-20, 25, -20);
|
|
626
|
+
*
|
|
627
|
+
* bezierVertex(0, 30, -20);
|
|
628
|
+
* bezierVertex(10, -25, -20);
|
|
629
|
+
* bezierVertex(-20, -30, -20);
|
|
630
|
+
*
|
|
631
|
+
* endShape();
|
|
632
|
+
* }
|
|
633
|
+
* </code>
|
|
634
|
+
* </div>
|
|
635
|
+
*/
|
|
636
|
+
function bezierVertex(x: number, y: number, u?: number, v?: number): void;
|
|
637
|
+
|
|
638
|
+
/**
|
|
639
|
+
*/
|
|
640
|
+
function bezierVertex(x: number, y: number, z: number, u?: number, v?: number): void;
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* Concludes the vertices of a custom shape.The beginShape() and `endShape()` functions
|
|
644
|
+
* allow for creating custom shapes in 2D or 3D.
|
|
645
|
+
* beginShape() begins adding vertices to a
|
|
646
|
+
* custom shape and `endShape()` stops adding them.The first parameter, `mode`, is optional. By default, the first and last
|
|
647
|
+
* vertices of a shape aren't connected. If the constant `CLOSE` is passed, as
|
|
648
|
+
* in `endShape(CLOSE)`, then the first and last vertices will be connected.
|
|
649
|
+
* When CLOSE mode is used for splines (with `splineVeertex()`), the shape is ended smoothly.The second parameter, `count`, is also optional. In WebGL mode, it’s more
|
|
650
|
+
* efficient to draw many copies of the same shape using a technique called
|
|
651
|
+
* instancing.
|
|
652
|
+
* The `count` parameter tells WebGL mode how many copies to draw. For
|
|
653
|
+
* example, calling `endShape(CLOSE, 400)` after drawing a custom shape will
|
|
654
|
+
* make it efficient to draw 400 copies. This feature requires
|
|
655
|
+
* writing a custom shader.After calling beginShape(), shapes can be
|
|
656
|
+
* built by calling vertex(),
|
|
657
|
+
* bezierVertex() and/or
|
|
658
|
+
* splineVertex(). Calling
|
|
659
|
+
* `endShape()` will stop adding vertices to the
|
|
660
|
+
* shape. Each shape will be outlined with the current stroke color and filled
|
|
661
|
+
* with the current fill color.Transformations such as translate(),
|
|
662
|
+
* rotate(), and
|
|
663
|
+
* scale() don't work between
|
|
664
|
+
* beginShape() and `endShape()`. It's also not
|
|
665
|
+
* possible to use other shapes, such as ellipse() or
|
|
666
|
+
* rect(), between
|
|
667
|
+
* beginShape() and `endShape()`.
|
|
668
|
+
*
|
|
669
|
+
* @param use CLOSE to close the shape
|
|
670
|
+
* @param number of times you want to draw/instance the shape (for WebGL mode).
|
|
671
|
+
* @example <div>
|
|
672
|
+
* <code>
|
|
673
|
+
* function setup() {
|
|
674
|
+
* createCanvas(100, 100);
|
|
675
|
+
*
|
|
676
|
+
* background(200);
|
|
677
|
+
*
|
|
678
|
+
* // Style the shapes.
|
|
679
|
+
* noFill();
|
|
680
|
+
*
|
|
681
|
+
* // Left triangle.
|
|
682
|
+
* beginShape();
|
|
683
|
+
* vertex(20, 20);
|
|
684
|
+
* vertex(45, 20);
|
|
685
|
+
* vertex(45, 80);
|
|
686
|
+
* endShape(CLOSE);
|
|
687
|
+
*
|
|
688
|
+
* // Right triangle.
|
|
689
|
+
* beginShape();
|
|
690
|
+
* vertex(50, 20);
|
|
691
|
+
* vertex(75, 20);
|
|
692
|
+
* vertex(75, 80);
|
|
693
|
+
* endShape();
|
|
694
|
+
*
|
|
695
|
+
* describe(
|
|
696
|
+
* 'Two sets of black lines drawn on a gray background. The three lines on the left form a right triangle. The two lines on the right form a right angle.'
|
|
697
|
+
* );
|
|
698
|
+
* }
|
|
699
|
+
* </code>
|
|
700
|
+
* </div>
|
|
701
|
+
*
|
|
702
|
+
* <div>
|
|
703
|
+
* <code>
|
|
704
|
+
* function setup() {
|
|
705
|
+
* createCanvas(100, 100);
|
|
706
|
+
* background(200);
|
|
707
|
+
*
|
|
708
|
+
* beginShape();
|
|
709
|
+
*
|
|
710
|
+
* splineVertex(32, 91);
|
|
711
|
+
* splineVertex(21, 17);
|
|
712
|
+
* splineVertex(68, 19);
|
|
713
|
+
* splineVertex(82, 91);
|
|
714
|
+
*
|
|
715
|
+
* endShape(CLOSE);
|
|
716
|
+
*
|
|
717
|
+
* describe(
|
|
718
|
+
* 'A curvy four-sided slightly lopsided blob.'
|
|
719
|
+
* );
|
|
720
|
+
* }
|
|
721
|
+
* </div>
|
|
722
|
+
* </code>
|
|
723
|
+
*
|
|
724
|
+
* <div>
|
|
725
|
+
* <code>
|
|
726
|
+
* // Note: A "uniform" is a global variable within a shader program.
|
|
727
|
+
*
|
|
728
|
+
* // Create a string with the vertex shader program.
|
|
729
|
+
* // The vertex shader is called for each vertex.
|
|
730
|
+
* let vertSrc = `#version 300 es
|
|
731
|
+
*
|
|
732
|
+
* precision mediump float;
|
|
733
|
+
*
|
|
734
|
+
* in vec3 aPosition;
|
|
735
|
+
* flat out int instanceID;
|
|
736
|
+
*
|
|
737
|
+
* uniform mat4 uModelViewMatrix;
|
|
738
|
+
* uniform mat4 uProjectionMatrix;
|
|
739
|
+
*
|
|
740
|
+
* void main() {
|
|
741
|
+
*
|
|
742
|
+
* // Copy the instance ID to the fragment shader.
|
|
743
|
+
* instanceID = gl_InstanceID;
|
|
744
|
+
* vec4 positionVec4 = vec4(aPosition, 1.0);
|
|
745
|
+
*
|
|
746
|
+
* // gl_InstanceID represents a numeric value for each instance.
|
|
747
|
+
* // Using gl_InstanceID allows us to move each instance separately.
|
|
748
|
+
* // Here we move each instance horizontally by ID * 23.
|
|
749
|
+
* float xOffset = float(gl_InstanceID) * 23.0;
|
|
750
|
+
*
|
|
751
|
+
* // Apply the offset to the final position.
|
|
752
|
+
* gl_Position = uProjectionMatrix * uModelViewMatrix * (positionVec4 -
|
|
753
|
+
* vec4(xOffset, 0.0, 0.0, 0.0));
|
|
754
|
+
* }
|
|
755
|
+
* `;
|
|
756
|
+
*
|
|
757
|
+
* // Create a string with the fragment shader program.
|
|
758
|
+
* // The fragment shader is called for each pixel.
|
|
759
|
+
* let fragSrc = `#version 300 es
|
|
760
|
+
*
|
|
761
|
+
* precision mediump float;
|
|
762
|
+
*
|
|
763
|
+
* out vec4 outColor;
|
|
764
|
+
* flat in int instanceID;
|
|
765
|
+
* uniform float numInstances;
|
|
766
|
+
*
|
|
767
|
+
* void main() {
|
|
768
|
+
* vec4 red = vec4(1.0, 0.0, 0.0, 1.0);
|
|
769
|
+
* vec4 blue = vec4(0.0, 0.0, 1.0, 1.0);
|
|
770
|
+
*
|
|
771
|
+
* // Normalize the instance ID.
|
|
772
|
+
* float normId = float(instanceID) / numInstances;
|
|
773
|
+
*
|
|
774
|
+
* // Mix between two colors using the normalized instance ID.
|
|
775
|
+
* outColor = mix(red, blue, normId);
|
|
776
|
+
* }
|
|
777
|
+
* `;
|
|
778
|
+
*
|
|
779
|
+
* function setup() {
|
|
780
|
+
* createCanvas(100, 100, WEBGL);
|
|
781
|
+
*
|
|
782
|
+
* // Create a p5.Shader object.
|
|
783
|
+
* let myShader = createShader(vertSrc, fragSrc);
|
|
784
|
+
*
|
|
785
|
+
* background(220);
|
|
786
|
+
*
|
|
787
|
+
* // Compile and apply the p5.Shader.
|
|
788
|
+
* shader(myShader);
|
|
789
|
+
*
|
|
790
|
+
* // Set the numInstances uniform.
|
|
791
|
+
* myShader.setUniform('numInstances', 4);
|
|
792
|
+
*
|
|
793
|
+
* // Translate the origin to help align the drawing.
|
|
794
|
+
* translate(25, -10);
|
|
795
|
+
*
|
|
796
|
+
* // Style the shapes.
|
|
797
|
+
* noStroke();
|
|
798
|
+
*
|
|
799
|
+
* // Draw the shapes.
|
|
800
|
+
* beginShape();
|
|
801
|
+
* vertex(0, 0);
|
|
802
|
+
* vertex(0, 20);
|
|
803
|
+
* vertex(20, 20);
|
|
804
|
+
* vertex(20, 0);
|
|
805
|
+
* vertex(0, 0);
|
|
806
|
+
* endShape(CLOSE, 4);
|
|
807
|
+
*
|
|
808
|
+
* describe('A row of four squares. Their colors transition from purple on the left to red on the right');
|
|
809
|
+
* }
|
|
810
|
+
* </code>
|
|
811
|
+
* </div>
|
|
812
|
+
*/
|
|
813
|
+
function endShape(mode?: CLOSE, count?: number): void;
|
|
814
|
+
|
|
815
|
+
/**
|
|
816
|
+
* Sets the normal vector for vertices in a custom 3D shape.3D shapes created with beginShape() and
|
|
817
|
+
* endShape() are made by connecting sets of
|
|
818
|
+
* points called vertices. Each vertex added with
|
|
819
|
+
* vertex() has a normal vector that points away
|
|
820
|
+
* from it. The normal vector controls how light reflects off the shape.`normal()` can be called two ways with different parameters to define the
|
|
821
|
+
* normal vector's components.The first way to call `normal()` has three parameters, `x`, `y`, and `z`.
|
|
822
|
+
* If `Number`s are passed, as in `normal(1, 2, 3)`, they set the x-, y-, and
|
|
823
|
+
* z-components of the normal vector.The second way to call `normal()` has one parameter, `vector`. If a
|
|
824
|
+
* p5.Vector object is passed, as in
|
|
825
|
+
* `normal(myVector)`, its components will be used to set the normal vector.`normal()` changes the normal vector of vertices added to a custom shape
|
|
826
|
+
* with vertex(). `normal()` must be called between
|
|
827
|
+
* the beginShape() and
|
|
828
|
+
* endShape() functions, just like
|
|
829
|
+
* vertex(). The normal vector set by calling
|
|
830
|
+
* `normal()` will affect all following vertices until `normal()` is called
|
|
831
|
+
* again:`beginShape();
|
|
832
|
+
*
|
|
833
|
+
* // Set the vertex normal.
|
|
834
|
+
* normal(-0.4, -0.4, 0.8);
|
|
835
|
+
*
|
|
836
|
+
* // Add a vertex.
|
|
837
|
+
* vertex(-30, -30, 0);
|
|
838
|
+
*
|
|
839
|
+
* // Set the vertex normal.
|
|
840
|
+
* normal(0, 0, 1);
|
|
841
|
+
*
|
|
842
|
+
* // Add vertices.
|
|
843
|
+
* vertex(30, -30, 0);
|
|
844
|
+
* vertex(30, 30, 0);
|
|
845
|
+
*
|
|
846
|
+
* // Set the vertex normal.
|
|
847
|
+
* normal(0.4, -0.4, 0.8);
|
|
848
|
+
*
|
|
849
|
+
* // Add a vertex.
|
|
850
|
+
* vertex(-30, 30, 0);
|
|
851
|
+
*
|
|
852
|
+
* endShape();`
|
|
853
|
+
*
|
|
854
|
+
* @param vertex normal as a <a href="#/p5.Vector">p5.Vector</a> object.
|
|
855
|
+
* @example <div>
|
|
856
|
+
* <code>
|
|
857
|
+
* // Click the and drag the mouse to view the scene from a different angle.
|
|
858
|
+
*
|
|
859
|
+
* function setup() {
|
|
860
|
+
* createCanvas(100, 100, WEBGL);
|
|
861
|
+
*
|
|
862
|
+
* describe(
|
|
863
|
+
* 'A colorful square on a black background. The square changes color and rotates when the user drags the mouse. Parts of its surface reflect light in different directions.'
|
|
864
|
+
* );
|
|
865
|
+
* }
|
|
866
|
+
*
|
|
867
|
+
* function draw() {
|
|
868
|
+
* background(0);
|
|
869
|
+
*
|
|
870
|
+
* // Enable orbiting with the mouse.
|
|
871
|
+
* orbitControl();
|
|
872
|
+
*
|
|
873
|
+
* // Style the shape.
|
|
874
|
+
* normalMaterial();
|
|
875
|
+
* noStroke();
|
|
876
|
+
*
|
|
877
|
+
* // Draw the shape.
|
|
878
|
+
* beginShape();
|
|
879
|
+
* vertex(-30, -30, 0);
|
|
880
|
+
* vertex(30, -30, 0);
|
|
881
|
+
* vertex(30, 30, 0);
|
|
882
|
+
* vertex(-30, 30, 0);
|
|
883
|
+
* endShape();
|
|
884
|
+
* }
|
|
885
|
+
* </code>
|
|
886
|
+
* </div>
|
|
887
|
+
*
|
|
888
|
+
* <div>
|
|
889
|
+
* <code>
|
|
890
|
+
* // Click the and drag the mouse to view the scene from a different angle.
|
|
891
|
+
*
|
|
892
|
+
* function setup() {
|
|
893
|
+
* createCanvas(100, 100, WEBGL);
|
|
894
|
+
*
|
|
895
|
+
* describe(
|
|
896
|
+
* 'A colorful square on a black background. The square changes color and rotates when the user drags the mouse. Parts of its surface reflect light in different directions.'
|
|
897
|
+
* );
|
|
898
|
+
* }
|
|
899
|
+
*
|
|
900
|
+
* function draw() {
|
|
901
|
+
* background(0);
|
|
902
|
+
*
|
|
903
|
+
* // Enable orbiting with the mouse.
|
|
904
|
+
* orbitControl();
|
|
905
|
+
*
|
|
906
|
+
* // Style the shape.
|
|
907
|
+
* normalMaterial();
|
|
908
|
+
* noStroke();
|
|
909
|
+
*
|
|
910
|
+
* // Draw the shape.
|
|
911
|
+
* // Use normal() to set vertex normals.
|
|
912
|
+
* beginShape();
|
|
913
|
+
* normal(-0.4, -0.4, 0.8);
|
|
914
|
+
* vertex(-30, -30, 0);
|
|
915
|
+
*
|
|
916
|
+
* normal(0, 0, 1);
|
|
917
|
+
* vertex(30, -30, 0);
|
|
918
|
+
* vertex(30, 30, 0);
|
|
919
|
+
*
|
|
920
|
+
* normal(0.4, -0.4, 0.8);
|
|
921
|
+
* vertex(-30, 30, 0);
|
|
922
|
+
* endShape();
|
|
923
|
+
* }
|
|
924
|
+
* </code>
|
|
925
|
+
* </div>
|
|
926
|
+
*
|
|
927
|
+
* <div class='notest'>
|
|
928
|
+
* <code>
|
|
929
|
+
* // Click the and drag the mouse to view the scene from a different angle.
|
|
930
|
+
*
|
|
931
|
+
* function setup() {
|
|
932
|
+
* createCanvas(100, 100, WEBGL);
|
|
933
|
+
*
|
|
934
|
+
* describe(
|
|
935
|
+
* 'A colorful square on a black background. The square changes color and rotates when the user drags the mouse. Parts of its surface reflect light in different directions.'
|
|
936
|
+
* );
|
|
937
|
+
* }
|
|
938
|
+
*
|
|
939
|
+
* function draw() {
|
|
940
|
+
* background(0);
|
|
941
|
+
*
|
|
942
|
+
* // Enable orbiting with the mouse.
|
|
943
|
+
* orbitControl();
|
|
944
|
+
*
|
|
945
|
+
* // Style the shape.
|
|
946
|
+
* normalMaterial();
|
|
947
|
+
* noStroke();
|
|
948
|
+
*
|
|
949
|
+
* // Create p5.Vector objects.
|
|
950
|
+
* let n1 = createVector(-0.4, -0.4, 0.8);
|
|
951
|
+
* let n2 = createVector(0, 0, 1);
|
|
952
|
+
* let n3 = createVector(0.4, -0.4, 0.8);
|
|
953
|
+
*
|
|
954
|
+
* // Draw the shape.
|
|
955
|
+
* // Use normal() to set vertex normals.
|
|
956
|
+
* beginShape();
|
|
957
|
+
* normal(n1);
|
|
958
|
+
* vertex(-30, -30, 0);
|
|
959
|
+
*
|
|
960
|
+
* normal(n2);
|
|
961
|
+
* vertex(30, -30, 0);
|
|
962
|
+
* vertex(30, 30, 0);
|
|
963
|
+
*
|
|
964
|
+
* normal(n3);
|
|
965
|
+
* vertex(-30, 30, 0);
|
|
966
|
+
* endShape();
|
|
967
|
+
* }
|
|
968
|
+
* </code>
|
|
969
|
+
* </div>
|
|
970
|
+
*/
|
|
971
|
+
function normal(vector: p5.Vector): void;
|
|
972
|
+
|
|
973
|
+
/**
|
|
974
|
+
* @param x-component of the vertex normal.
|
|
975
|
+
* @param y-component of the vertex normal.
|
|
976
|
+
* @param z-component of the vertex normal.
|
|
977
|
+
*/
|
|
978
|
+
function normal(x: number, y: number, z: number): void;
|
|
979
|
+
|
|
980
|
+
/**
|
|
981
|
+
* Sets the shader's vertex property or attribute variables.A vertex property, or vertex attribute, is a variable belonging to a vertex in a shader. p5.js provides some
|
|
982
|
+
* default properties, such as `aPosition`, `aNormal`, `aVertexColor`, etc. These are
|
|
983
|
+
* set using vertex(), normal()
|
|
984
|
+
* and fill() respectively. Custom properties can also
|
|
985
|
+
* be defined within beginShape() and
|
|
986
|
+
* endShape().The first parameter, `propertyName`, is a string with the property's name.
|
|
987
|
+
* This is the same variable name which should be declared in the shader, such as
|
|
988
|
+
* `in vec3 aProperty`, similar to .`setUniform()`.The second parameter, `data`, is the value assigned to the shader variable. This
|
|
989
|
+
* value will be applied to subsequent vertices created with
|
|
990
|
+
* vertex(). It can be a Number or an array of numbers,
|
|
991
|
+
* and in the shader program the type can be declared according to the WebGL
|
|
992
|
+
* specification. Common types include `float`, `vec2`, `vec3`, `vec4` or matrices.See also the vertexProperty() method on
|
|
993
|
+
* Geometry objects.
|
|
994
|
+
*
|
|
995
|
+
* @for p5
|
|
996
|
+
* @param the name of the vertex attribute.
|
|
997
|
+
* @param the data tied to the vertex attribute.
|
|
998
|
+
* @example <div>
|
|
999
|
+
* <code>
|
|
1000
|
+
* const vertSrc = `#version 300 es
|
|
1001
|
+
* precision mediump float;
|
|
1002
|
+
* uniform mat4 uModelViewMatrix;
|
|
1003
|
+
* uniform mat4 uProjectionMatrix;
|
|
1004
|
+
*
|
|
1005
|
+
* in vec3 aPosition;
|
|
1006
|
+
* in vec2 aOffset;
|
|
1007
|
+
*
|
|
1008
|
+
* void main(){
|
|
1009
|
+
* vec4 positionVec4 = vec4(aPosition.xyz, 1.0);
|
|
1010
|
+
* positionVec4.xy += aOffset;
|
|
1011
|
+
* gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;
|
|
1012
|
+
* }
|
|
1013
|
+
* `;
|
|
1014
|
+
*
|
|
1015
|
+
* const fragSrc = `#version 300 es
|
|
1016
|
+
* precision mediump float;
|
|
1017
|
+
* out vec4 outColor;
|
|
1018
|
+
* void main(){
|
|
1019
|
+
* outColor = vec4(0.0, 1.0, 1.0, 1.0);
|
|
1020
|
+
* }
|
|
1021
|
+
* `;
|
|
1022
|
+
*
|
|
1023
|
+
* function setup(){
|
|
1024
|
+
* createCanvas(100, 100, WEBGL);
|
|
1025
|
+
*
|
|
1026
|
+
* // Create and use the custom shader.
|
|
1027
|
+
* const myShader = createShader(vertSrc, fragSrc);
|
|
1028
|
+
* shader(myShader);
|
|
1029
|
+
*
|
|
1030
|
+
* describe('A wobbly, cyan circle on a gray background.');
|
|
1031
|
+
* }
|
|
1032
|
+
*
|
|
1033
|
+
* function draw(){
|
|
1034
|
+
* // Set the styles
|
|
1035
|
+
* background(125);
|
|
1036
|
+
* noStroke();
|
|
1037
|
+
*
|
|
1038
|
+
* // Draw the circle.
|
|
1039
|
+
* beginShape();
|
|
1040
|
+
* for (let i = 0; i < 30; i++){
|
|
1041
|
+
* const x = 40 * cos(i/30 * TWO_PI);
|
|
1042
|
+
* const y = 40 * sin(i/30 * TWO_PI);
|
|
1043
|
+
*
|
|
1044
|
+
* // Apply some noise to the coordinates.
|
|
1045
|
+
* const xOff = 10 * noise(x + millis()/1000) - 5;
|
|
1046
|
+
* const yOff = 10 * noise(y + millis()/1000) - 5;
|
|
1047
|
+
*
|
|
1048
|
+
* // Apply these noise values to the following vertex.
|
|
1049
|
+
* vertexProperty('aOffset', [xOff, yOff]);
|
|
1050
|
+
* vertex(x, y);
|
|
1051
|
+
* }
|
|
1052
|
+
* endShape(CLOSE);
|
|
1053
|
+
* }
|
|
1054
|
+
* </code>
|
|
1055
|
+
* </div>
|
|
1056
|
+
*
|
|
1057
|
+
* <div>
|
|
1058
|
+
* <code>
|
|
1059
|
+
* let myShader;
|
|
1060
|
+
* const cols = 10;
|
|
1061
|
+
* const rows = 10;
|
|
1062
|
+
* const cellSize = 6;
|
|
1063
|
+
*
|
|
1064
|
+
* const vertSrc = `#version 300 es
|
|
1065
|
+
* precision mediump float;
|
|
1066
|
+
* uniform mat4 uProjectionMatrix;
|
|
1067
|
+
* uniform mat4 uModelViewMatrix;
|
|
1068
|
+
*
|
|
1069
|
+
* in vec3 aPosition;
|
|
1070
|
+
* in vec3 aNormal;
|
|
1071
|
+
* in vec3 aVertexColor;
|
|
1072
|
+
* in float aDistance;
|
|
1073
|
+
*
|
|
1074
|
+
* out vec3 vVertexColor;
|
|
1075
|
+
*
|
|
1076
|
+
* void main(){
|
|
1077
|
+
* vec4 positionVec4 = vec4(aPosition, 1.0);
|
|
1078
|
+
* positionVec4.xyz += aDistance * aNormal * 2.0;;
|
|
1079
|
+
* vVertexColor = aVertexColor;
|
|
1080
|
+
* gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;
|
|
1081
|
+
* }
|
|
1082
|
+
* `;
|
|
1083
|
+
*
|
|
1084
|
+
* const fragSrc = `#version 300 es
|
|
1085
|
+
* precision mediump float;
|
|
1086
|
+
*
|
|
1087
|
+
* in vec3 vVertexColor;
|
|
1088
|
+
* out vec4 outColor;
|
|
1089
|
+
*
|
|
1090
|
+
* void main(){
|
|
1091
|
+
* outColor = vec4(vVertexColor, 1.0);
|
|
1092
|
+
* }
|
|
1093
|
+
* `;
|
|
1094
|
+
*
|
|
1095
|
+
* function setup(){
|
|
1096
|
+
* createCanvas(100, 100, WEBGL);
|
|
1097
|
+
*
|
|
1098
|
+
* // Create and apply the custom shader.
|
|
1099
|
+
* myShader = createShader(vertSrc, fragSrc);
|
|
1100
|
+
* shader(myShader);
|
|
1101
|
+
* noStroke();
|
|
1102
|
+
* describe('A blue grid, which moves away from the mouse position, on a gray background.');
|
|
1103
|
+
* }
|
|
1104
|
+
*
|
|
1105
|
+
* function draw(){
|
|
1106
|
+
* background(200);
|
|
1107
|
+
*
|
|
1108
|
+
* // Draw the grid in the middle of the screen.
|
|
1109
|
+
* translate(-cols*cellSize/2, -rows*cellSize/2);
|
|
1110
|
+
* beginShape(QUADS);
|
|
1111
|
+
* for (let i = 0; i < cols; i++) {
|
|
1112
|
+
* for (let j = 0; j < rows; j++) {
|
|
1113
|
+
*
|
|
1114
|
+
* // Calculate the cell position.
|
|
1115
|
+
* let x = i * cellSize;
|
|
1116
|
+
* let y = j * cellSize;
|
|
1117
|
+
*
|
|
1118
|
+
* fill(j/rows*255, j/cols*255, 255);
|
|
1119
|
+
*
|
|
1120
|
+
* // Calculate the distance from the corner of each cell to the mouse.
|
|
1121
|
+
* let distance = dist(x, y, mouseX, mouseY);
|
|
1122
|
+
*
|
|
1123
|
+
* // Send the distance to the shader.
|
|
1124
|
+
* vertexProperty('aDistance', min(distance, 100));
|
|
1125
|
+
*
|
|
1126
|
+
* vertex(x, y);
|
|
1127
|
+
* vertex(x + cellSize, y);
|
|
1128
|
+
* vertex(x + cellSize, y + cellSize);
|
|
1129
|
+
* vertex(x, y + cellSize);
|
|
1130
|
+
* }
|
|
1131
|
+
* }
|
|
1132
|
+
* endShape();
|
|
1133
|
+
* }
|
|
1134
|
+
* </code>
|
|
1135
|
+
* </div>
|
|
1136
|
+
*/
|
|
1137
|
+
function vertexProperty(attributeName: string, data: number | number[]): void;
|
|
1138
|
+
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
export default function vertex(p5: any, fn: any): void;
|