p5 2.2.1-rc.0 → 2.2.1
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 -6
- package/dist/accessibility/describe.js +4 -26
- package/dist/accessibility/index.js +5 -6
- package/dist/accessibility/outputs.js +6 -38
- package/dist/app.js +5 -6
- package/dist/color/color_conversion.js +5 -6
- 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 +59 -357
- package/dist/{constants-DEJVKr9Z.js → constants-DQyACdzq.js} +11 -61
- package/dist/core/constants.js +1 -1
- package/dist/core/environment.js +26 -158
- package/dist/core/filterShaders.js +1 -1
- package/dist/core/friendly_errors/fes_core.js +1 -1
- package/dist/core/friendly_errors/file_errors.js +1 -1
- package/dist/core/friendly_errors/index.js +1 -1
- package/dist/core/friendly_errors/param_validator.js +1 -1
- package/dist/core/friendly_errors/sketch_verifier.js +1 -1
- package/dist/core/helpers.js +1 -1
- package/dist/core/init.js +5 -6
- package/dist/core/internationalization.js +1 -1
- package/dist/core/legacy.js +5 -6
- package/dist/core/main.js +5 -6
- package/dist/core/p5.Graphics.js +4 -5
- package/dist/core/p5.Renderer.js +3 -4
- package/dist/core/p5.Renderer2D.js +5 -6
- package/dist/core/p5.Renderer3D.js +4 -5
- package/dist/core/rendering.js +4 -5
- package/dist/core/structure.js +13 -52
- package/dist/core/transform.js +32 -176
- package/dist/{creating_reading-CgHCHxqN.js → creating_reading-ZXzcZEsb.js} +3 -196
- package/dist/data/local_storage.js +4 -30
- package/dist/dom/dom.js +24 -159
- package/dist/dom/index.js +2 -2
- package/dist/dom/p5.Element.js +31 -208
- package/dist/dom/p5.File.js +1 -32
- package/dist/dom/p5.MediaElement.js +10 -113
- package/dist/events/acceleration.js +11 -64
- package/dist/events/keyboard.js +13 -81
- package/dist/events/pointer.js +18 -160
- package/dist/image/const.js +1 -1
- package/dist/image/filterRenderer2D.js +4 -5
- package/dist/image/image.js +4 -5
- package/dist/image/index.js +4 -5
- package/dist/image/loading_displaying.js +4 -5
- package/dist/image/p5.Image.js +3 -4
- package/dist/image/pixels.js +17 -100
- package/dist/io/files.js +4 -5
- package/dist/io/index.js +4 -5
- package/dist/io/p5.Table.js +66 -158
- package/dist/io/p5.TableRow.js +48 -71
- package/dist/io/p5.XML.js +6 -99
- package/dist/io/utilities.js +8 -3
- package/dist/{main-_RXV5Lx8.js → main-DvN69W3f.js} +13 -42
- package/dist/math/Matrices/Matrix.js +87 -126
- package/dist/math/Matrices/MatrixNumjs.js +1 -5
- package/dist/math/calculation.js +10 -112
- package/dist/math/index.js +1 -1
- package/dist/math/math.js +2 -12
- package/dist/math/noise.js +5 -32
- package/dist/math/p5.Matrix.js +3 -3
- package/dist/math/p5.Vector.js +104 -345
- package/dist/math/random.js +5 -32
- package/dist/math/trigonometry.js +15 -105
- package/dist/{p5.Renderer-QoFcvj3f.js → p5.Renderer-D-5LdCRz.js} +25 -178
- package/dist/{rendering-CsICjEXA.js → rendering-h9unX5K0.js} +254 -1156
- package/dist/shape/2d_primitives.js +33 -194
- package/dist/shape/attributes.js +12 -73
- package/dist/shape/curves.js +30 -95
- package/dist/shape/custom_shapes.js +63 -144
- package/dist/shape/index.js +2 -2
- package/dist/shape/vertex.js +21 -106
- package/dist/strands/p5.strands.js +248 -46
- package/dist/type/index.js +3 -4
- package/dist/type/p5.Font.js +4 -49
- package/dist/type/textCore.js +5 -158
- package/dist/utilities/conversion.js +17 -104
- package/dist/utilities/time_date.js +3 -40
- package/dist/utilities/utility_functions.js +6 -48
- package/dist/webgl/3d_primitives.js +4 -5
- package/dist/webgl/GeometryBuilder.js +1 -2
- package/dist/webgl/ShapeBuilder.js +22 -2
- package/dist/webgl/enums.js +1 -1
- package/dist/webgl/index.js +4 -5
- package/dist/webgl/interaction.js +6 -33
- package/dist/webgl/light.js +4 -5
- package/dist/webgl/loading.js +12 -46
- package/dist/webgl/material.js +4 -5
- package/dist/webgl/p5.Camera.js +4 -5
- package/dist/webgl/p5.DataArray.js +0 -4
- package/dist/webgl/p5.Framebuffer.js +4 -5
- package/dist/webgl/p5.Geometry.js +12 -106
- package/dist/webgl/p5.Quat.js +1 -1
- package/dist/webgl/p5.RendererGL.js +7 -18
- package/dist/webgl/p5.Shader.js +12 -36
- package/dist/webgl/p5.Texture.js +4 -5
- package/dist/webgl/text.js +4 -5
- package/dist/webgl/utils.js +4 -5
- package/dist/webgpu/index.js +1 -1
- package/dist/webgpu/p5.RendererWebGPU.js +529 -208
- package/dist/webgpu/shaders/color.js +32 -17
- package/dist/webgpu/shaders/filters/base.js +18 -7
- package/dist/webgpu/shaders/font.js +52 -40
- package/dist/webgpu/shaders/line.js +50 -36
- package/dist/webgpu/shaders/material.js +90 -83
- package/dist/webgpu/strands_wgslBackend.js +5 -2
- package/lib/p5.esm.js +5576 -7811
- package/lib/p5.esm.min.js +1 -1
- package/lib/p5.js +5576 -7811
- package/lib/p5.min.js +1 -1
- package/lib/p5.webgpu.esm.js +786 -453
- package/lib/p5.webgpu.js +786 -453
- package/lib/p5.webgpu.min.js +1 -1
- package/package.json +13 -13
- package/types/global.d.ts +16905 -16783
- package/types/p5.d.ts +11142 -11081
package/dist/shape/attributes.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { p as CORNER, t as CORNERS, u as RADIUS, v as CENTER, w as ROUND, x as SQUARE, y as PROJECT, z as BEVEL, I as MITER } from '../constants-
|
|
1
|
+
import { p as CORNER, t as CORNERS, u as RADIUS, v as CENTER, w as ROUND, x as SQUARE, y as PROJECT, z as BEVEL, I as MITER } from '../constants-DQyACdzq.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @module Shape
|
|
@@ -41,8 +41,6 @@ function attributes(p5, fn){
|
|
|
41
41
|
* @chainable
|
|
42
42
|
*
|
|
43
43
|
* @example
|
|
44
|
-
* <div>
|
|
45
|
-
* <code>
|
|
46
44
|
* function setup() {
|
|
47
45
|
* createCanvas(100, 100);
|
|
48
46
|
*
|
|
@@ -60,11 +58,8 @@ function attributes(p5, fn){
|
|
|
60
58
|
*
|
|
61
59
|
* describe('A white circle with a gray circle at its center. Both circles have black outlines.');
|
|
62
60
|
* }
|
|
63
|
-
* </code>
|
|
64
|
-
* </div>
|
|
65
61
|
*
|
|
66
|
-
*
|
|
67
|
-
* <code>
|
|
62
|
+
* @example
|
|
68
63
|
* function setup() {
|
|
69
64
|
* createCanvas(100, 100);
|
|
70
65
|
*
|
|
@@ -82,8 +77,6 @@ function attributes(p5, fn){
|
|
|
82
77
|
*
|
|
83
78
|
* describe('A white circle with a gray circle at its top-left corner. Both circles have black outlines.');
|
|
84
79
|
* }
|
|
85
|
-
* </code>
|
|
86
|
-
* </div>
|
|
87
80
|
*/
|
|
88
81
|
fn.ellipseMode = function(m) {
|
|
89
82
|
// p5._validateParameters('ellipseMode', arguments);
|
|
@@ -112,8 +105,6 @@ function attributes(p5, fn){
|
|
|
112
105
|
* @chainable
|
|
113
106
|
*
|
|
114
107
|
* @example
|
|
115
|
-
* <div>
|
|
116
|
-
* <code>
|
|
117
108
|
* let heart;
|
|
118
109
|
*
|
|
119
110
|
* async function setup() {
|
|
@@ -134,11 +125,8 @@ function attributes(p5, fn){
|
|
|
134
125
|
* image(heart, 20, 60, 16, 16);
|
|
135
126
|
* image(heart, 40, 60, 32, 32);
|
|
136
127
|
* }
|
|
137
|
-
* </code>
|
|
138
|
-
* </div>
|
|
139
128
|
*
|
|
140
|
-
*
|
|
141
|
-
* <code>
|
|
129
|
+
* @example
|
|
142
130
|
* function setup() {
|
|
143
131
|
* createCanvas(100, 100, WEBGL);
|
|
144
132
|
*
|
|
@@ -148,11 +136,8 @@ function attributes(p5, fn){
|
|
|
148
136
|
*
|
|
149
137
|
* describe('A white circle on a gray background.');
|
|
150
138
|
* }
|
|
151
|
-
* </code>
|
|
152
|
-
* </div>
|
|
153
139
|
*
|
|
154
|
-
*
|
|
155
|
-
* <code>
|
|
140
|
+
* @example
|
|
156
141
|
* function setup() {
|
|
157
142
|
* createCanvas(100, 100, WEBGL);
|
|
158
143
|
*
|
|
@@ -165,8 +150,6 @@ function attributes(p5, fn){
|
|
|
165
150
|
*
|
|
166
151
|
* describe('A pixelated white circle on a gray background.');
|
|
167
152
|
* }
|
|
168
|
-
* </code>
|
|
169
|
-
* </div>
|
|
170
153
|
*/
|
|
171
154
|
fn.noSmooth = function() {
|
|
172
155
|
if (!this._renderer.isP3D) {
|
|
@@ -209,8 +192,6 @@ function attributes(p5, fn){
|
|
|
209
192
|
* @chainable
|
|
210
193
|
*
|
|
211
194
|
* @example
|
|
212
|
-
* <div>
|
|
213
|
-
* <code>
|
|
214
195
|
* function setup() {
|
|
215
196
|
* createCanvas(100, 100);
|
|
216
197
|
*
|
|
@@ -226,11 +207,8 @@ function attributes(p5, fn){
|
|
|
226
207
|
*
|
|
227
208
|
* describe('A small gray square drawn at the top-left corner of a white square.');
|
|
228
209
|
* }
|
|
229
|
-
* </code>
|
|
230
|
-
* </div>
|
|
231
210
|
*
|
|
232
|
-
*
|
|
233
|
-
* <code>
|
|
211
|
+
* @example
|
|
234
212
|
* function setup() {
|
|
235
213
|
* createCanvas(100, 100);
|
|
236
214
|
*
|
|
@@ -246,11 +224,8 @@ function attributes(p5, fn){
|
|
|
246
224
|
*
|
|
247
225
|
* describe('A small gray square drawn at the center of a white square.');
|
|
248
226
|
* }
|
|
249
|
-
* </code>
|
|
250
|
-
* </div>
|
|
251
227
|
*
|
|
252
|
-
*
|
|
253
|
-
* <code>
|
|
228
|
+
* @example
|
|
254
229
|
* function setup() {
|
|
255
230
|
* createCanvas(100, 100);
|
|
256
231
|
*
|
|
@@ -262,11 +237,8 @@ function attributes(p5, fn){
|
|
|
262
237
|
*
|
|
263
238
|
* describe('A white square.');
|
|
264
239
|
* }
|
|
265
|
-
* </code>
|
|
266
|
-
* </div>
|
|
267
240
|
*
|
|
268
|
-
*
|
|
269
|
-
* <code>
|
|
241
|
+
* @example
|
|
270
242
|
* function setup() {
|
|
271
243
|
* createCanvas(100, 100);
|
|
272
244
|
*
|
|
@@ -282,8 +254,6 @@ function attributes(p5, fn){
|
|
|
282
254
|
*
|
|
283
255
|
* describe('A small gray square drawn at the center of a white square.');
|
|
284
256
|
* }
|
|
285
|
-
* </code>
|
|
286
|
-
* </div>
|
|
287
257
|
*/
|
|
288
258
|
fn.rectMode = function(m) {
|
|
289
259
|
// p5._validateParameters('rectMode', arguments);
|
|
@@ -313,8 +283,6 @@ function attributes(p5, fn){
|
|
|
313
283
|
* @chainable
|
|
314
284
|
*
|
|
315
285
|
* @example
|
|
316
|
-
* <div>
|
|
317
|
-
* <code>
|
|
318
286
|
* let heart;
|
|
319
287
|
*
|
|
320
288
|
* async function setup() {
|
|
@@ -336,11 +304,8 @@ function attributes(p5, fn){
|
|
|
336
304
|
* image(heart, 20, 60, 16, 16);
|
|
337
305
|
* image(heart, 40, 60, 32, 32);
|
|
338
306
|
* }
|
|
339
|
-
* </code>
|
|
340
|
-
* </div>
|
|
341
307
|
*
|
|
342
|
-
*
|
|
343
|
-
* <code>
|
|
308
|
+
* @example
|
|
344
309
|
* function setup() {
|
|
345
310
|
* createCanvas(100, 100, WEBGL);
|
|
346
311
|
*
|
|
@@ -350,11 +315,8 @@ function attributes(p5, fn){
|
|
|
350
315
|
*
|
|
351
316
|
* describe('A white circle on a gray background.');
|
|
352
317
|
* }
|
|
353
|
-
* </code>
|
|
354
|
-
* </div>
|
|
355
318
|
*
|
|
356
|
-
*
|
|
357
|
-
* <code>
|
|
319
|
+
* @example
|
|
358
320
|
* function setup() {
|
|
359
321
|
* createCanvas(100, 100, WEBGL);
|
|
360
322
|
*
|
|
@@ -367,8 +329,6 @@ function attributes(p5, fn){
|
|
|
367
329
|
*
|
|
368
330
|
* describe('A pixelated white circle on a gray background.');
|
|
369
331
|
* }
|
|
370
|
-
* </code>
|
|
371
|
-
* </div>
|
|
372
332
|
*/
|
|
373
333
|
fn.smooth = function() {
|
|
374
334
|
if (!this._renderer.isP3D) {
|
|
@@ -395,8 +355,6 @@ function attributes(p5, fn){
|
|
|
395
355
|
* @param {(ROUND|SQUARE|PROJECT)} cap either ROUND, SQUARE, or PROJECT
|
|
396
356
|
* @chainable
|
|
397
357
|
* @example
|
|
398
|
-
* <div>
|
|
399
|
-
* <code>
|
|
400
358
|
* function setup() {
|
|
401
359
|
* createCanvas(100, 100);
|
|
402
360
|
*
|
|
@@ -420,8 +378,6 @@ function attributes(p5, fn){
|
|
|
420
378
|
* 'Three horizontal lines. The top line has rounded ends, the middle line has squared ends, and the bottom line has longer, squared ends.'
|
|
421
379
|
* );
|
|
422
380
|
* }
|
|
423
|
-
* </code>
|
|
424
|
-
* </div>
|
|
425
381
|
*/
|
|
426
382
|
fn.strokeCap = function(cap) {
|
|
427
383
|
// p5._validateParameters('strokeCap', arguments);
|
|
@@ -450,8 +406,6 @@ function attributes(p5, fn){
|
|
|
450
406
|
* @param {(MITER|BEVEL|ROUND)} join either MITER, BEVEL, or ROUND
|
|
451
407
|
* @chainable
|
|
452
408
|
* @example
|
|
453
|
-
* <div>
|
|
454
|
-
* <code>
|
|
455
409
|
* function setup() {
|
|
456
410
|
* createCanvas(100, 100);
|
|
457
411
|
*
|
|
@@ -471,11 +425,8 @@ function attributes(p5, fn){
|
|
|
471
425
|
*
|
|
472
426
|
* describe('A right-facing arrowhead shape with a pointed tip in center of canvas.');
|
|
473
427
|
* }
|
|
474
|
-
* </code>
|
|
475
|
-
* </div>
|
|
476
428
|
*
|
|
477
|
-
*
|
|
478
|
-
* <code>
|
|
429
|
+
* @example
|
|
479
430
|
* function setup() {
|
|
480
431
|
* createCanvas(100, 100);
|
|
481
432
|
*
|
|
@@ -495,11 +446,8 @@ function attributes(p5, fn){
|
|
|
495
446
|
*
|
|
496
447
|
* describe('A right-facing arrowhead shape with a flat tip in center of canvas.');
|
|
497
448
|
* }
|
|
498
|
-
* </code>
|
|
499
|
-
* </div>
|
|
500
449
|
*
|
|
501
|
-
*
|
|
502
|
-
* <code>
|
|
450
|
+
* @example
|
|
503
451
|
* function setup() {
|
|
504
452
|
* createCanvas(100, 100);
|
|
505
453
|
*
|
|
@@ -519,8 +467,6 @@ function attributes(p5, fn){
|
|
|
519
467
|
*
|
|
520
468
|
* describe('A right-facing arrowhead shape with a rounded tip in center of canvas.');
|
|
521
469
|
* }
|
|
522
|
-
* </code>
|
|
523
|
-
* </div>
|
|
524
470
|
*/
|
|
525
471
|
fn.strokeJoin = function(join) {
|
|
526
472
|
// p5._validateParameters('strokeJoin', arguments);
|
|
@@ -545,8 +491,6 @@ function attributes(p5, fn){
|
|
|
545
491
|
* @param {Number} weight the weight of the stroke (in pixels).
|
|
546
492
|
* @chainable
|
|
547
493
|
* @example
|
|
548
|
-
* <div>
|
|
549
|
-
* <code>
|
|
550
494
|
* function setup() {
|
|
551
495
|
* createCanvas(100, 100);
|
|
552
496
|
*
|
|
@@ -565,11 +509,8 @@ function attributes(p5, fn){
|
|
|
565
509
|
*
|
|
566
510
|
* describe('Three horizontal black lines. The top line is thin, the middle is medium, and the bottom is thick.');
|
|
567
511
|
* }
|
|
568
|
-
* </code>
|
|
569
|
-
* </div>
|
|
570
512
|
*
|
|
571
|
-
*
|
|
572
|
-
* <code>
|
|
513
|
+
* @example
|
|
573
514
|
* function setup() {
|
|
574
515
|
* createCanvas(100, 100);
|
|
575
516
|
*
|
|
@@ -586,8 +527,6 @@ function attributes(p5, fn){
|
|
|
586
527
|
*
|
|
587
528
|
* describe('Two horizontal black lines. The top line is thin and the bottom is five times thicker than the top.');
|
|
588
529
|
* }
|
|
589
|
-
* </code>
|
|
590
|
-
* </div>
|
|
591
530
|
*/
|
|
592
531
|
fn.strokeWeight = function(w) {
|
|
593
532
|
// p5._validateParameters('strokeWeight', arguments);
|
package/dist/shape/curves.js
CHANGED
|
@@ -39,8 +39,6 @@ function curves(p5, fn){
|
|
|
39
39
|
* @chainable
|
|
40
40
|
*
|
|
41
41
|
* @example
|
|
42
|
-
* <div>
|
|
43
|
-
* <code>
|
|
44
42
|
* function setup() {
|
|
45
43
|
* createCanvas(100, 100);
|
|
46
44
|
*
|
|
@@ -72,11 +70,8 @@ function curves(p5, fn){
|
|
|
72
70
|
* 'A gray square with three curves. A black s-curve has two straight, red lines that extend from its ends. The endpoints of all the curves are marked with dots.'
|
|
73
71
|
* );
|
|
74
72
|
* }
|
|
75
|
-
* </code>
|
|
76
|
-
* </div>
|
|
77
73
|
*
|
|
78
|
-
*
|
|
79
|
-
* <code>
|
|
74
|
+
* @example
|
|
80
75
|
* // Click the mouse near the red dot in the top-left corner
|
|
81
76
|
* // and drag to change the curve's shape.
|
|
82
77
|
*
|
|
@@ -137,11 +132,8 @@ function curves(p5, fn){
|
|
|
137
132
|
* y2 = mouseY;
|
|
138
133
|
* }
|
|
139
134
|
* }
|
|
140
|
-
* </code>
|
|
141
|
-
* </div>
|
|
142
135
|
*
|
|
143
|
-
*
|
|
144
|
-
* <code>
|
|
136
|
+
* @example
|
|
145
137
|
* function setup() {
|
|
146
138
|
* createCanvas(100, 100);
|
|
147
139
|
*
|
|
@@ -156,11 +148,8 @@ function curves(p5, fn){
|
|
|
156
148
|
*
|
|
157
149
|
* describe('A red balloon in a blue sky.');
|
|
158
150
|
* }
|
|
159
|
-
* </code>
|
|
160
|
-
* </div>
|
|
161
151
|
*
|
|
162
|
-
*
|
|
163
|
-
* <code>
|
|
152
|
+
* @example
|
|
164
153
|
* function setup() {
|
|
165
154
|
* createCanvas(100, 100, WEBGL);
|
|
166
155
|
*
|
|
@@ -180,10 +169,7 @@ function curves(p5, fn){
|
|
|
180
169
|
* // Draw the balloon string.
|
|
181
170
|
* line(0, 0, 0, 0, 20, 0);
|
|
182
171
|
* }
|
|
183
|
-
* </code>
|
|
184
|
-
* </div>
|
|
185
172
|
*/
|
|
186
|
-
|
|
187
173
|
/**
|
|
188
174
|
* @method bezier
|
|
189
175
|
* @param {Number} x1
|
|
@@ -248,8 +234,6 @@ function curves(p5, fn){
|
|
|
248
234
|
* @return {Number} coordinate of the point on the curve.
|
|
249
235
|
*
|
|
250
236
|
* @example
|
|
251
|
-
* <div>
|
|
252
|
-
* <code>
|
|
253
237
|
* function setup() {
|
|
254
238
|
* createCanvas(100, 100);
|
|
255
239
|
*
|
|
@@ -291,11 +275,8 @@ function curves(p5, fn){
|
|
|
291
275
|
*
|
|
292
276
|
* describe('A black s-curve on a gray square. The endpoints and center of the curve are marked with white circles.');
|
|
293
277
|
* }
|
|
294
|
-
* </code>
|
|
295
|
-
* </div>
|
|
296
278
|
*
|
|
297
|
-
*
|
|
298
|
-
* <code>
|
|
279
|
+
* @example
|
|
299
280
|
* function setup() {
|
|
300
281
|
* createCanvas(100, 100);
|
|
301
282
|
*
|
|
@@ -328,8 +309,6 @@ function curves(p5, fn){
|
|
|
328
309
|
* fill(255);
|
|
329
310
|
* circle(x, y, 5);
|
|
330
311
|
* }
|
|
331
|
-
* </code>
|
|
332
|
-
* </div>
|
|
333
312
|
*/
|
|
334
313
|
fn.bezierPoint = function(a, b, c, d, t) {
|
|
335
314
|
// p5._validateParameters('bezierPoint', arguments);
|
|
@@ -377,8 +356,6 @@ function curves(p5, fn){
|
|
|
377
356
|
* @return {Number} coordinate of a point on the tangent line.
|
|
378
357
|
*
|
|
379
358
|
* @example
|
|
380
|
-
* <div>
|
|
381
|
-
* <code>
|
|
382
359
|
* function setup() {
|
|
383
360
|
* createCanvas(100, 100);
|
|
384
361
|
*
|
|
@@ -446,8 +423,6 @@ function curves(p5, fn){
|
|
|
446
423
|
* 'A black s-curve on a gray square. The endpoints and center of the curve are marked with white circles. Red tangent lines extend from the white circles.'
|
|
447
424
|
* );
|
|
448
425
|
* }
|
|
449
|
-
* </code>
|
|
450
|
-
* </div>
|
|
451
426
|
*/
|
|
452
427
|
fn.bezierTangent = function(a, b, c, d, t) {
|
|
453
428
|
// p5._validateParameters('bezierTangent', arguments);
|
|
@@ -489,9 +464,6 @@ function curves(p5, fn){
|
|
|
489
464
|
* @chainable
|
|
490
465
|
*
|
|
491
466
|
* @example
|
|
492
|
-
*
|
|
493
|
-
* <div>
|
|
494
|
-
* <code>
|
|
495
467
|
* function setup() {
|
|
496
468
|
* createCanvas(200, 200);
|
|
497
469
|
* background(240);
|
|
@@ -509,30 +481,27 @@ function curves(p5, fn){
|
|
|
509
481
|
*
|
|
510
482
|
* describe('A black spline passes smoothly through four points');
|
|
511
483
|
* }
|
|
512
|
-
* </code>
|
|
513
|
-
* </div>
|
|
514
484
|
*
|
|
515
|
-
*
|
|
516
|
-
* <code>
|
|
485
|
+
* @example
|
|
517
486
|
* function setup() {
|
|
518
487
|
* createCanvas(200, 200);
|
|
519
488
|
* background(245);
|
|
520
|
-
*
|
|
489
|
+
*
|
|
521
490
|
* // Ensure the curve includes both end spans p0->p1 and p2->p3
|
|
522
491
|
* splineProperty('ends', INCLUDE);
|
|
523
|
-
*
|
|
492
|
+
*
|
|
524
493
|
* // Control / anchor points
|
|
525
494
|
* const p0 = createVector(30, 160);
|
|
526
495
|
* const p1 = createVector(60, 40);
|
|
527
496
|
* const p2 = createVector(140, 40);
|
|
528
497
|
* const p3 = createVector(170, 160);
|
|
529
|
-
*
|
|
498
|
+
*
|
|
530
499
|
* // Draw the spline that passes through ALL four points (INCLUDE)
|
|
531
500
|
* noFill();
|
|
532
501
|
* stroke(0);
|
|
533
502
|
* strokeWeight(2);
|
|
534
503
|
* spline(p0.x, p0.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y);
|
|
535
|
-
*
|
|
504
|
+
*
|
|
536
505
|
* // Draw markers + labels
|
|
537
506
|
* fill(255);
|
|
538
507
|
* stroke(0);
|
|
@@ -541,21 +510,18 @@ function curves(p5, fn){
|
|
|
541
510
|
* circle(p1.x, p1.y, r);
|
|
542
511
|
* circle(p2.x, p2.y, r);
|
|
543
512
|
* circle(p3.x, p3.y, r);
|
|
544
|
-
*
|
|
513
|
+
*
|
|
545
514
|
* noStroke();
|
|
546
515
|
* fill(0);
|
|
547
516
|
* text('p0', p0.x - 14, p0.y + 14);
|
|
548
517
|
* text('p1', p1.x - 14, p1.y - 8);
|
|
549
518
|
* text('p2', p2.x + 4, p2.y - 8);
|
|
550
519
|
* text('p3', p3.x + 4, p3.y + 14);
|
|
551
|
-
*
|
|
520
|
+
*
|
|
552
521
|
* describe('A black Catmull-Rom spline passes through p0, p1, p2, p3 with endpoints included.');
|
|
553
522
|
* }
|
|
554
|
-
*
|
|
555
|
-
*
|
|
556
|
-
*
|
|
557
|
-
* <div>
|
|
558
|
-
* <code>
|
|
523
|
+
*
|
|
524
|
+
* @example
|
|
559
525
|
* function setup() {
|
|
560
526
|
* createCanvas(100, 100);
|
|
561
527
|
*
|
|
@@ -590,11 +556,8 @@ function curves(p5, fn){
|
|
|
590
556
|
* 'A gray square with a curve drawn in three segments. The curve is a sideways U shape with red segments on top and bottom, and a black segment on the right. The endpoints of all the segments are marked with dots.'
|
|
591
557
|
* );
|
|
592
558
|
* }
|
|
593
|
-
* </code>
|
|
594
|
-
* </div>
|
|
595
559
|
*
|
|
596
|
-
*
|
|
597
|
-
* <code>
|
|
560
|
+
* @example
|
|
598
561
|
* let x1 = 5;
|
|
599
562
|
* let y1 = 26;
|
|
600
563
|
* let isChanging = false;
|
|
@@ -655,11 +618,8 @@ function curves(p5, fn){
|
|
|
655
618
|
* y1 = mouseY;
|
|
656
619
|
* }
|
|
657
620
|
* }
|
|
658
|
-
* </code>
|
|
659
|
-
* </div>
|
|
660
621
|
*
|
|
661
|
-
*
|
|
662
|
-
* <code>
|
|
622
|
+
* @example
|
|
663
623
|
* function setup() {
|
|
664
624
|
* createCanvas(100, 100);
|
|
665
625
|
*
|
|
@@ -677,11 +637,8 @@ function curves(p5, fn){
|
|
|
677
637
|
*
|
|
678
638
|
* describe('A red balloon in a blue sky.');
|
|
679
639
|
* }
|
|
680
|
-
* </code>
|
|
681
|
-
* </div>
|
|
682
640
|
*
|
|
683
|
-
*
|
|
684
|
-
* <code>
|
|
641
|
+
* @example
|
|
685
642
|
* function setup() {
|
|
686
643
|
* createCanvas(100, 100, WEBGL);
|
|
687
644
|
*
|
|
@@ -704,10 +661,7 @@ function curves(p5, fn){
|
|
|
704
661
|
* // Draw the balloon string.
|
|
705
662
|
* line(0, 10, 0, 0, 30, 0);
|
|
706
663
|
* }
|
|
707
|
-
* </code>
|
|
708
|
-
* </div>
|
|
709
664
|
*/
|
|
710
|
-
|
|
711
665
|
/**
|
|
712
666
|
* @method spline
|
|
713
667
|
* @param {Number} x1
|
|
@@ -767,8 +721,6 @@ function curves(p5, fn){
|
|
|
767
721
|
* @return {Number} coordinate of a point on the curve.
|
|
768
722
|
*
|
|
769
723
|
* @example
|
|
770
|
-
* <div>
|
|
771
|
-
* <code>
|
|
772
724
|
* function setup() {
|
|
773
725
|
* createCanvas(100, 100);
|
|
774
726
|
*
|
|
@@ -809,11 +761,8 @@ function curves(p5, fn){
|
|
|
809
761
|
*
|
|
810
762
|
* describe('A black curve on a gray square. The endpoints and center of the curve are marked with white circles.');
|
|
811
763
|
* }
|
|
812
|
-
* </code>
|
|
813
|
-
* </div>
|
|
814
764
|
*
|
|
815
|
-
*
|
|
816
|
-
* <code>
|
|
765
|
+
* @example
|
|
817
766
|
* function setup() {
|
|
818
767
|
* createCanvas(100, 100);
|
|
819
768
|
*
|
|
@@ -846,47 +795,44 @@ function curves(p5, fn){
|
|
|
846
795
|
* fill(255);
|
|
847
796
|
* circle(x, y, 5);
|
|
848
797
|
* }
|
|
849
|
-
*
|
|
850
|
-
*
|
|
851
|
-
*
|
|
852
|
-
* <div>
|
|
853
|
-
* <code>
|
|
798
|
+
*
|
|
799
|
+
* @example
|
|
854
800
|
* let p0, p1, p2, p3;
|
|
855
|
-
*
|
|
801
|
+
*
|
|
856
802
|
* function setup() {
|
|
857
803
|
* createCanvas(200, 200);
|
|
858
804
|
* splineProperty('ends', INCLUDE); // make endpoints part of the curve
|
|
859
|
-
*
|
|
805
|
+
*
|
|
860
806
|
* // Four points forming a gentle arch
|
|
861
807
|
* p0 = createVector(30, 160);
|
|
862
808
|
* p1 = createVector(60, 50);
|
|
863
809
|
* p2 = createVector(140, 50);
|
|
864
810
|
* p3 = createVector(170, 160);
|
|
865
|
-
*
|
|
811
|
+
*
|
|
866
812
|
* describe('Black spline through p0–p3. A red dot marks the location at parameter t on p1->p2 using splinePoint.');
|
|
867
813
|
* }
|
|
868
|
-
*
|
|
814
|
+
*
|
|
869
815
|
* function draw() {
|
|
870
816
|
* background(245);
|
|
871
|
-
*
|
|
817
|
+
*
|
|
872
818
|
* // Draw the spline for context
|
|
873
819
|
* noFill();
|
|
874
820
|
* stroke(0);
|
|
875
821
|
* strokeWeight(2);
|
|
876
822
|
* spline(p0.x, p0.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y);
|
|
877
|
-
*
|
|
823
|
+
*
|
|
878
824
|
* // Map mouse X to t in [0, 1] (span p1->p2)
|
|
879
825
|
* let t = constrain(map(mouseX, 0, width, 0, 1), 0, 1);
|
|
880
|
-
*
|
|
826
|
+
*
|
|
881
827
|
* // Evaluate the curve point by axis (splinePoint works one axis at a time)
|
|
882
828
|
* let x = splinePoint(p0.x, p1.x, p2.x, p3.x, t);
|
|
883
829
|
* let y = splinePoint(p0.y, p1.y, p2.y, p3.y, t);
|
|
884
|
-
*
|
|
830
|
+
*
|
|
885
831
|
* // Marker at the evaluated position
|
|
886
832
|
* noStroke();
|
|
887
833
|
* fill('red');
|
|
888
834
|
* circle(x, y, 8);
|
|
889
|
-
*
|
|
835
|
+
*
|
|
890
836
|
* // Draw control/anchor points
|
|
891
837
|
* stroke(0);
|
|
892
838
|
* strokeWeight(1);
|
|
@@ -896,7 +842,7 @@ function curves(p5, fn){
|
|
|
896
842
|
* circle(p1.x, p1.y, r);
|
|
897
843
|
* circle(p2.x, p2.y, r);
|
|
898
844
|
* circle(p3.x, p3.y, r);
|
|
899
|
-
*
|
|
845
|
+
*
|
|
900
846
|
* // Labels + UI hint
|
|
901
847
|
* noStroke();
|
|
902
848
|
* fill(20);
|
|
@@ -907,11 +853,7 @@ function curves(p5, fn){
|
|
|
907
853
|
* text('p3', p3.x + 4, p3.y + 14);
|
|
908
854
|
* text('t = ' + nf(t, 1, 2) + ' (p1→p2)', 8, 16);
|
|
909
855
|
* }
|
|
910
|
-
* </code>
|
|
911
|
-
* </div>
|
|
912
|
-
*
|
|
913
856
|
*/
|
|
914
|
-
|
|
915
857
|
fn.splinePoint = function(a, b, c, d, t) {
|
|
916
858
|
const s = this._renderer.states.splineProperties.tightness,
|
|
917
859
|
t3 = t * t * t,
|
|
@@ -954,8 +896,6 @@ function curves(p5, fn){
|
|
|
954
896
|
* @return {Number} coordinate of a point on the tangent line.
|
|
955
897
|
*
|
|
956
898
|
* @example
|
|
957
|
-
* <div>
|
|
958
|
-
* <code>
|
|
959
899
|
* function setup() {
|
|
960
900
|
* createCanvas(120, 120);
|
|
961
901
|
* describe('A black spline on a gray canvas. A red dot moves along the curve on its own. A short line shows the tangent direction at the dot.');
|
|
@@ -994,11 +934,8 @@ function curves(p5, fn){
|
|
|
994
934
|
* fill('red');
|
|
995
935
|
* circle(px, py, 7);
|
|
996
936
|
* }
|
|
997
|
-
* </code>
|
|
998
|
-
* </div>
|
|
999
937
|
*
|
|
1000
|
-
*
|
|
1001
|
-
* <code>
|
|
938
|
+
* @example
|
|
1002
939
|
* function setup() {
|
|
1003
940
|
* createCanvas(100, 100);
|
|
1004
941
|
*
|
|
@@ -1064,8 +1001,6 @@ function curves(p5, fn){
|
|
|
1064
1001
|
* 'A black curve on a gray square. A white circle moves back and forth along the curve.'
|
|
1065
1002
|
* );
|
|
1066
1003
|
* }
|
|
1067
|
-
* </code>
|
|
1068
|
-
* </div>
|
|
1069
1004
|
*/
|
|
1070
1005
|
fn.splineTangent = function(a, b, c, d, t) {
|
|
1071
1006
|
const s = this._renderer.states.splineProperties.tightness,
|