p5 2.0.4 → 2.0.5
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/README.md +1 -1
- package/dist/accessibility/color_namer.js +4 -4
- package/dist/accessibility/index.js +4 -4
- package/dist/accessibility/outputs.js +1 -1
- package/dist/app.js +4 -4
- package/dist/color/color_conversion.js +4 -4
- package/dist/color/index.js +1 -1
- package/dist/color/setting.js +1 -1
- package/dist/{constants-C2DVjshm.js → constants-8IpwyBct.js} +1 -1
- package/dist/core/constants.js +1 -1
- package/dist/core/environment.js +1 -1
- 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 +1 -1
- package/dist/core/friendly_errors/sketch_verifier.js +1 -1
- package/dist/core/helpers.js +1 -1
- package/dist/core/init.js +4 -4
- package/dist/core/legacy.js +4 -4
- package/dist/core/main.js +4 -4
- package/dist/core/p5.Graphics.js +3 -3
- package/dist/core/p5.Renderer.js +2 -2
- package/dist/core/p5.Renderer2D.js +4 -4
- package/dist/core/rendering.js +3 -3
- package/dist/dom/dom.js +1 -1
- package/dist/dom/index.js +1 -1
- package/dist/dom/p5.Element.js +1 -1
- package/dist/dom/p5.MediaElement.js +1 -1
- package/dist/image/const.js +1 -1
- package/dist/image/filterRenderer2D.js +3 -3
- package/dist/image/image.js +3 -3
- package/dist/image/index.js +3 -3
- package/dist/image/loading_displaying.js +3 -3
- package/dist/image/p5.Image.js +2 -2
- package/dist/io/files.js +3 -3
- package/dist/io/index.js +3 -3
- package/dist/{main-rEhlsQtb.js → main-B3Z63C6j.js} +3 -3
- 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/p5.Matrix.js +1 -1
- package/dist/math/p5.Vector.js +1 -1
- package/dist/math/trigonometry.js +1 -1
- package/dist/{p5.Renderer-DO9wIL55.js → p5.Renderer-DoDzbpcT.js} +1 -1
- package/dist/{rendering-CpHn8PfG.js → rendering-BELwvfI6.js} +3 -3
- package/dist/shape/2d_primitives.js +1 -1
- package/dist/shape/attributes.js +1 -1
- package/dist/shape/curves.js +143 -74
- package/dist/shape/custom_shapes.js +261 -277
- package/dist/shape/index.js +1 -1
- package/dist/type/index.js +2 -2
- package/dist/type/p5.Font.js +2 -2
- package/dist/type/textCore.js +2 -2
- package/dist/webgl/3d_primitives.js +3 -3
- package/dist/webgl/GeometryBuilder.js +1 -1
- package/dist/webgl/ShaderGenerator.js +10 -7
- package/dist/webgl/ShapeBuilder.js +1 -1
- package/dist/webgl/index.js +3 -3
- package/dist/webgl/interaction.js +1 -1
- package/dist/webgl/light.js +3 -3
- package/dist/webgl/loading.js +3 -3
- package/dist/webgl/material.js +3 -3
- package/dist/webgl/p5.Camera.js +3 -3
- package/dist/webgl/p5.Framebuffer.js +3 -3
- package/dist/webgl/p5.Geometry.js +1 -1
- package/dist/webgl/p5.Quat.js +1 -1
- package/dist/webgl/p5.RendererGL.js +3 -3
- package/dist/webgl/p5.Shader.js +3 -3
- package/dist/webgl/p5.Texture.js +3 -3
- package/dist/webgl/text.js +3 -3
- package/lib/p5.esm.js +414 -358
- package/lib/p5.esm.min.js +1 -1
- package/lib/p5.js +414 -358
- package/lib/p5.min.js +1 -1
- package/package.json +1 -1
- package/types/core/main.d.ts +87 -71
- package/types/global.d.ts +87 -71
- package/types/p5.d.ts +87 -71
- package/types/shape/curves.d.ts +130 -56
- package/types/shape/custom_shapes.d.ts +188 -252
package/lib/p5.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! p5.js v2.0.
|
|
1
|
+
/*! p5.js v2.0.5 September 1, 2025 */
|
|
2
2
|
var p5 = (function () {
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
@@ -15,7 +15,7 @@ var p5 = (function () {
|
|
|
15
15
|
* @property {String} VERSION
|
|
16
16
|
* @final
|
|
17
17
|
*/
|
|
18
|
-
const VERSION = '2.0.
|
|
18
|
+
const VERSION = '2.0.5';
|
|
19
19
|
|
|
20
20
|
// GRAPHICS RENDERER
|
|
21
21
|
/**
|
|
@@ -25131,67 +25131,73 @@ var p5 = (function () {
|
|
|
25131
25131
|
};
|
|
25132
25132
|
|
|
25133
25133
|
|
|
25134
|
+
|
|
25134
25135
|
/**
|
|
25135
|
-
*
|
|
25136
|
+
* Connects points with a smooth curve (a spline).
|
|
25136
25137
|
*
|
|
25137
|
-
* `splineVertex()` adds a curved segment to custom shapes.
|
|
25138
|
-
* it creates
|
|
25139
|
-
* <a href="#/p5/
|
|
25140
|
-
* between the
|
|
25138
|
+
* `splineVertex()` adds a curved segment to custom shapes.
|
|
25139
|
+
* The curve it creates follows the same rules as the ones
|
|
25140
|
+
* made with the <a href="#/p5/spline">spline()</a> function.
|
|
25141
|
+
* `splineVertex()` must be called between the
|
|
25142
|
+
* <a href="#/p5/beginShape">beginShape()</a> and
|
|
25141
25143
|
* <a href="#/p5/endShape">endShape()</a> functions.
|
|
25142
25144
|
*
|
|
25143
25145
|
* Spline curves can form shapes and curves that slope gently. They’re like
|
|
25144
|
-
* cables that are attached to a set of points.
|
|
25145
|
-
*
|
|
25146
|
-
* least four times between
|
|
25146
|
+
* cables that are attached to a set of points. `splineVertex()` draws a smooth
|
|
25147
|
+
* curve through the points you give it.
|
|
25147
25148
|
* <a href="#/p5/beginShape">beginShape()</a> and
|
|
25148
25149
|
* <a href="#/p5/endShape">endShape()</a> in order to draw a curve:
|
|
25149
25150
|
*
|
|
25151
|
+
*
|
|
25152
|
+
* If you provide three points, the spline will pass through them.
|
|
25153
|
+
* It works the same way with any number of points.
|
|
25154
|
+
*
|
|
25155
|
+
*
|
|
25156
|
+
*
|
|
25150
25157
|
* ```js
|
|
25151
25158
|
* beginShape();
|
|
25152
25159
|
*
|
|
25153
|
-
* // Add the first
|
|
25154
|
-
* splineVertex(
|
|
25160
|
+
* // Add the first point.
|
|
25161
|
+
* splineVertex(25, 80);
|
|
25155
25162
|
*
|
|
25156
|
-
* // Add the
|
|
25157
|
-
* splineVertex(
|
|
25158
|
-
* splineVertex(21, 17);
|
|
25163
|
+
* // Add the second point.
|
|
25164
|
+
* splineVertex(20, 30);
|
|
25159
25165
|
*
|
|
25160
|
-
* // Add the
|
|
25161
|
-
* splineVertex(
|
|
25166
|
+
* // Add the last point.
|
|
25167
|
+
* splineVertex(85, 60);
|
|
25162
25168
|
*
|
|
25163
25169
|
* endShape();
|
|
25164
25170
|
* ```
|
|
25165
|
-
*
|
|
25166
|
-
*
|
|
25167
|
-
*
|
|
25168
|
-
*
|
|
25169
|
-
* `
|
|
25170
|
-
*
|
|
25171
|
+
*
|
|
25172
|
+
* <img src="assets/openCurveSpline.png"></img>
|
|
25173
|
+
*
|
|
25174
|
+
*
|
|
25175
|
+
* Passing in `CLOSE` to `endShape()` closes the spline smoothly.
|
|
25171
25176
|
* ```js
|
|
25172
25177
|
* beginShape();
|
|
25173
|
-
*
|
|
25174
|
-
* // Add the first
|
|
25175
|
-
* splineVertex(
|
|
25176
|
-
*
|
|
25177
|
-
*
|
|
25178
|
-
*
|
|
25179
|
-
*
|
|
25180
|
-
*
|
|
25181
|
-
*
|
|
25182
|
-
*
|
|
25183
|
-
*
|
|
25184
|
-
*
|
|
25185
|
-
* // Uncomment the next line to draw the segment to the second control point.
|
|
25186
|
-
* // splineVertex(32, 91);
|
|
25187
|
-
*
|
|
25188
|
-
* endShape();
|
|
25178
|
+
*
|
|
25179
|
+
* // Add the first point.
|
|
25180
|
+
* splineVertex(25, 80);
|
|
25181
|
+
*
|
|
25182
|
+
* // Add the second point.
|
|
25183
|
+
* splineVertex(20, 30);
|
|
25184
|
+
*
|
|
25185
|
+
* // Add the second point.
|
|
25186
|
+
* splineVertex(85, 60);
|
|
25187
|
+
*
|
|
25188
|
+
* endShape(CLOSE);
|
|
25189
25189
|
* ```
|
|
25190
|
-
*
|
|
25191
|
-
*
|
|
25192
|
-
*
|
|
25193
|
-
*
|
|
25194
|
-
*
|
|
25190
|
+
*
|
|
25191
|
+
* <img src="assets/closeCurveSpline.png"></img>
|
|
25192
|
+
*
|
|
25193
|
+
*
|
|
25194
|
+
* By default (`ends: INCLUDE`), the curve passes through
|
|
25195
|
+
* all the points you add with `splineVertex()`, similar to
|
|
25196
|
+
* the <a href="#/p5/spline">spline()</a> function. To draw only
|
|
25197
|
+
* the middle span p1->p2 (skipping p0->p1 and p2->p3), set
|
|
25198
|
+
* `splineProperty('ends', EXCLUDE)`. You don’t need to duplicate
|
|
25199
|
+
* vertices to draw those spans.
|
|
25200
|
+
*
|
|
25195
25201
|
* Spline curves can also be drawn in 3D using WebGL mode. The 3D version of
|
|
25196
25202
|
* `splineVertex()` has three arguments because each point has x-, y-, and
|
|
25197
25203
|
* z-coordinates. By default, the vertex’s z-coordinate is set to 0.
|
|
@@ -25209,46 +25215,29 @@ var p5 = (function () {
|
|
|
25209
25215
|
* <code>
|
|
25210
25216
|
* function setup() {
|
|
25211
25217
|
* createCanvas(100, 100);
|
|
25212
|
-
*
|
|
25213
|
-
* background(
|
|
25214
|
-
*
|
|
25215
|
-
* // Style the shape.
|
|
25218
|
+
*
|
|
25219
|
+
* background(220);
|
|
25216
25220
|
* noFill();
|
|
25217
25221
|
* strokeWeight(1);
|
|
25218
|
-
*
|
|
25219
|
-
* // Start drawing the shape.
|
|
25222
|
+
*
|
|
25220
25223
|
* beginShape();
|
|
25221
|
-
*
|
|
25222
|
-
*
|
|
25223
|
-
* splineVertex(
|
|
25224
|
-
*
|
|
25225
|
-
* // Add the anchor points.
|
|
25226
|
-
* splineVertex(21, 17);
|
|
25227
|
-
* splineVertex(68, 19);
|
|
25228
|
-
*
|
|
25229
|
-
* // Add the second control point.
|
|
25230
|
-
* splineVertex(84, 91);
|
|
25231
|
-
*
|
|
25232
|
-
* // Stop drawing the shape.
|
|
25224
|
+
* splineVertex(25, 80);
|
|
25225
|
+
* splineVertex(20, 30);
|
|
25226
|
+
* splineVertex(85, 60);
|
|
25233
25227
|
* endShape();
|
|
25234
|
-
*
|
|
25235
|
-
* // Style the anchor and control points.
|
|
25228
|
+
*
|
|
25236
25229
|
* strokeWeight(5);
|
|
25237
|
-
*
|
|
25238
|
-
* // Draw the anchor points in black.
|
|
25239
25230
|
* stroke(0);
|
|
25240
|
-
*
|
|
25241
|
-
* point(
|
|
25242
|
-
*
|
|
25243
|
-
*
|
|
25244
|
-
*
|
|
25245
|
-
* point(32, 91);
|
|
25246
|
-
* point(84, 91);
|
|
25247
|
-
*
|
|
25231
|
+
*
|
|
25232
|
+
* point(25, 80);
|
|
25233
|
+
* point(20, 30);
|
|
25234
|
+
* point(85, 60);
|
|
25235
|
+
*
|
|
25248
25236
|
* describe(
|
|
25249
|
-
* '
|
|
25237
|
+
* 'On a gray background, a black spline passes through three marked points.'
|
|
25250
25238
|
* );
|
|
25251
25239
|
* }
|
|
25240
|
+
*
|
|
25252
25241
|
* </code>
|
|
25253
25242
|
* </div>
|
|
25254
25243
|
*
|
|
@@ -25256,204 +25245,63 @@ var p5 = (function () {
|
|
|
25256
25245
|
* <code>
|
|
25257
25246
|
* function setup() {
|
|
25258
25247
|
* createCanvas(100, 100);
|
|
25248
|
+
* background(220);
|
|
25259
25249
|
*
|
|
25260
|
-
* background(200);
|
|
25261
|
-
*
|
|
25262
|
-
* // Style the shape.
|
|
25263
|
-
* noFill();
|
|
25264
|
-
* strokeWeight(1);
|
|
25265
|
-
*
|
|
25266
|
-
* // Start drawing the shape.
|
|
25267
25250
|
* beginShape();
|
|
25268
|
-
*
|
|
25269
|
-
*
|
|
25270
|
-
* splineVertex(
|
|
25271
|
-
*
|
|
25272
|
-
*
|
|
25273
|
-
* // Add the anchor points.
|
|
25274
|
-
* splineVertex(21, 17);
|
|
25275
|
-
* splineVertex(68, 19);
|
|
25276
|
-
*
|
|
25277
|
-
* // Add the second control point.
|
|
25278
|
-
* splineVertex(84, 91);
|
|
25279
|
-
*
|
|
25280
|
-
* // Stop drawing the shape.
|
|
25281
|
-
* endShape();
|
|
25282
|
-
*
|
|
25283
|
-
* // Style the anchor and control points.
|
|
25284
|
-
* strokeWeight(5);
|
|
25285
|
-
*
|
|
25286
|
-
* // Draw the anchor points in black.
|
|
25287
|
-
* stroke(0);
|
|
25288
|
-
* point(21, 17);
|
|
25289
|
-
* point(68, 19);
|
|
25290
|
-
*
|
|
25291
|
-
* // Draw the control points in red.
|
|
25292
|
-
* stroke(255, 0, 0);
|
|
25293
|
-
* point(32, 91);
|
|
25294
|
-
* point(84, 91);
|
|
25251
|
+
* splineVertex(25, 80);
|
|
25252
|
+
* splineVertex(20, 30);
|
|
25253
|
+
* splineVertex(85, 60);
|
|
25254
|
+
* endShape(CLOSE);
|
|
25295
25255
|
*
|
|
25296
25256
|
* describe(
|
|
25297
|
-
* '
|
|
25257
|
+
* 'On a gray background, a closed black spline with a white interior forms a triangular shape with smooth corners.'
|
|
25298
25258
|
* );
|
|
25299
25259
|
* }
|
|
25260
|
+
*
|
|
25300
25261
|
* </code>
|
|
25301
25262
|
* </div>
|
|
25302
25263
|
*
|
|
25303
25264
|
* <div>
|
|
25304
25265
|
* <code>
|
|
25305
|
-
*
|
|
25306
|
-
*
|
|
25307
|
-
*
|
|
25308
|
-
*
|
|
25266
|
+
* let ringInnerRadius, ringWidth;
|
|
25267
|
+
* let radius, dRadius;
|
|
25268
|
+
* let theta, dTheta;
|
|
25269
|
+
* let time, dTime;
|
|
25270
|
+
* let vertexCount, unit, offset;
|
|
25309
25271
|
*
|
|
25310
|
-
*
|
|
25311
|
-
*
|
|
25312
|
-
* strokeWeight(1);
|
|
25313
|
-
*
|
|
25314
|
-
* // Start drawing the shape.
|
|
25315
|
-
* beginShape();
|
|
25316
|
-
*
|
|
25317
|
-
* // Add the first control point and draw a segment to it.
|
|
25318
|
-
* splineVertex(32, 91);
|
|
25319
|
-
* splineVertex(32, 91);
|
|
25320
|
-
*
|
|
25321
|
-
* // Add the anchor points.
|
|
25322
|
-
* splineVertex(21, 17);
|
|
25323
|
-
* splineVertex(68, 19);
|
|
25324
|
-
*
|
|
25325
|
-
* // Add the second control point and draw a segment to it.
|
|
25326
|
-
* splineVertex(84, 91);
|
|
25327
|
-
* splineVertex(84, 91);
|
|
25328
|
-
*
|
|
25329
|
-
* // Stop drawing the shape.
|
|
25330
|
-
* endShape();
|
|
25331
|
-
*
|
|
25332
|
-
* // Style the anchor and control points.
|
|
25333
|
-
* strokeWeight(5);
|
|
25334
|
-
*
|
|
25335
|
-
* // Draw the anchor points in black.
|
|
25336
|
-
* stroke(0);
|
|
25337
|
-
* point(21, 17);
|
|
25338
|
-
* point(68, 19);
|
|
25339
|
-
*
|
|
25340
|
-
* // Draw the control points in red.
|
|
25341
|
-
* stroke(255, 0, 0);
|
|
25342
|
-
* point(32, 91);
|
|
25343
|
-
* point(84, 91);
|
|
25344
|
-
*
|
|
25345
|
-
* describe(
|
|
25346
|
-
* 'A black U curve drawn upside down on a gray background. The curve passes from one red dot through two black dots and ends at another red dot.'
|
|
25347
|
-
* );
|
|
25348
|
-
* }
|
|
25349
|
-
* </code>
|
|
25350
|
-
* </div>
|
|
25272
|
+
* function setup() {
|
|
25273
|
+
* createCanvas(400, 400);
|
|
25351
25274
|
*
|
|
25352
|
-
*
|
|
25353
|
-
*
|
|
25354
|
-
*
|
|
25355
|
-
*
|
|
25275
|
+
* vertexCount = 15;
|
|
25276
|
+
* unit = createVector(1, 0);
|
|
25277
|
+
* dTheta = TAU / vertexCount;
|
|
25278
|
+
* dTime = 0.004;
|
|
25356
25279
|
*
|
|
25357
|
-
*
|
|
25358
|
-
*
|
|
25359
|
-
* let isChanging = false;
|
|
25280
|
+
* ringInnerRadius = 25;
|
|
25281
|
+
* ringWidth = 5 * ringInnerRadius;
|
|
25360
25282
|
*
|
|
25361
|
-
*
|
|
25362
|
-
* createCanvas(100, 100);
|
|
25283
|
+
* offset = width;
|
|
25363
25284
|
*
|
|
25364
25285
|
* describe(
|
|
25365
|
-
* 'A
|
|
25286
|
+
* 'A white blob with a black outline changes its shape over time.'
|
|
25366
25287
|
* );
|
|
25367
25288
|
* }
|
|
25368
25289
|
*
|
|
25369
25290
|
* function draw() {
|
|
25370
|
-
* background(
|
|
25291
|
+
* background(220);
|
|
25292
|
+
* strokeWeight(2);
|
|
25293
|
+
* translate(width / 2, height / 2);
|
|
25371
25294
|
*
|
|
25372
|
-
*
|
|
25373
|
-
* noFill();
|
|
25374
|
-
* stroke(0);
|
|
25375
|
-
* strokeWeight(1);
|
|
25295
|
+
* time = dTime * frameCount;
|
|
25376
25296
|
*
|
|
25377
|
-
* // Start drawing the shape.
|
|
25378
25297
|
* beginShape();
|
|
25379
|
-
*
|
|
25380
|
-
*
|
|
25381
|
-
*
|
|
25382
|
-
*
|
|
25383
|
-
*
|
|
25384
|
-
* // Add the anchor points.
|
|
25385
|
-
* splineVertex(21, 17);
|
|
25386
|
-
* splineVertex(68, 19);
|
|
25387
|
-
*
|
|
25388
|
-
* // Add the second control point and draw a segment to it.
|
|
25389
|
-
* splineVertex(84, 91);
|
|
25390
|
-
* splineVertex(84, 91);
|
|
25391
|
-
*
|
|
25392
|
-
* // Stop drawing the shape.
|
|
25393
|
-
* endShape();
|
|
25394
|
-
*
|
|
25395
|
-
* // Style the anchor and control points.
|
|
25396
|
-
* strokeWeight(5);
|
|
25397
|
-
*
|
|
25398
|
-
* // Draw the anchor points in black.
|
|
25399
|
-
* stroke(0);
|
|
25400
|
-
* point(21, 17);
|
|
25401
|
-
* point(68, 19);
|
|
25402
|
-
*
|
|
25403
|
-
* // Draw the control points in red.
|
|
25404
|
-
* stroke(255, 0, 0);
|
|
25405
|
-
* point(x1, y1);
|
|
25406
|
-
* point(84, 91);
|
|
25407
|
-
* }
|
|
25408
|
-
*
|
|
25409
|
-
* // Start changing the first control point if the user clicks near it.
|
|
25410
|
-
* function mousePressed() {
|
|
25411
|
-
* if (dist(mouseX, mouseY, x1, y1) < 20) {
|
|
25412
|
-
* isChanging = true;
|
|
25298
|
+
* for (let i = 0; i < vertexCount; i++) {
|
|
25299
|
+
* unit.rotate(dTheta);
|
|
25300
|
+
* dRadius = noise(offset + unit.x, offset + unit.y, time) * ringWidth;
|
|
25301
|
+
* radius = ringInnerRadius + dRadius;
|
|
25302
|
+
* splineVertex(radius * unit.x, radius * unit.y);
|
|
25413
25303
|
* }
|
|
25414
|
-
*
|
|
25415
|
-
*
|
|
25416
|
-
* // Stop changing the first control point when the user releases the mouse.
|
|
25417
|
-
* function mouseReleased() {
|
|
25418
|
-
* isChanging = false;
|
|
25419
|
-
* }
|
|
25420
|
-
*
|
|
25421
|
-
* // Update the first control point while the user drags the mouse.
|
|
25422
|
-
* function mouseDragged() {
|
|
25423
|
-
* if (isChanging === true) {
|
|
25424
|
-
* x1 = mouseX;
|
|
25425
|
-
* y1 = mouseY;
|
|
25426
|
-
* }
|
|
25427
|
-
* }
|
|
25428
|
-
* </code>
|
|
25429
|
-
* </div>
|
|
25430
|
-
*
|
|
25431
|
-
* <div>
|
|
25432
|
-
* <code>
|
|
25433
|
-
* function setup() {
|
|
25434
|
-
* createCanvas(100, 100);
|
|
25435
|
-
*
|
|
25436
|
-
* background(200);
|
|
25437
|
-
*
|
|
25438
|
-
* // Start drawing the shape.
|
|
25439
|
-
* beginShape();
|
|
25440
|
-
*
|
|
25441
|
-
* // Add the first control point and draw a segment to it.
|
|
25442
|
-
* splineVertex(32, 91);
|
|
25443
|
-
* splineVertex(32, 91);
|
|
25444
|
-
*
|
|
25445
|
-
* // Add the anchor points.
|
|
25446
|
-
* splineVertex(21, 17);
|
|
25447
|
-
* splineVertex(68, 19);
|
|
25448
|
-
*
|
|
25449
|
-
* // Add the second control point.
|
|
25450
|
-
* splineVertex(84, 91);
|
|
25451
|
-
* splineVertex(84, 91);
|
|
25452
|
-
*
|
|
25453
|
-
* // Stop drawing the shape.
|
|
25454
|
-
* endShape();
|
|
25455
|
-
*
|
|
25456
|
-
* describe('A ghost shape drawn in white on a gray background.');
|
|
25304
|
+
* endShape(CLOSE);
|
|
25457
25305
|
* }
|
|
25458
25306
|
* </code>
|
|
25459
25307
|
* </div>
|
|
@@ -25542,25 +25390,83 @@ var p5 = (function () {
|
|
|
25542
25390
|
};
|
|
25543
25391
|
|
|
25544
25392
|
/**
|
|
25545
|
-
*
|
|
25393
|
+
* Gets or sets a given spline property.
|
|
25394
|
+
*
|
|
25395
|
+
* Use `splineProperty()` to adjust the behavior of splines
|
|
25396
|
+
* created with `splineVertex()` or `spline()`. You can control
|
|
25397
|
+
* two key aspects of a spline: its end behavior (`ends`) and
|
|
25398
|
+
* its curvature (`tightness`).
|
|
25399
|
+
*
|
|
25400
|
+
* By default, the ends property is set to `INCLUDE`, which means
|
|
25401
|
+
* the spline passes through every point, including the endpoints.
|
|
25402
|
+
* You can also set it to `EXCLUDE` i.e. `splineProperty('ends', EXCLUDE)`,
|
|
25403
|
+
* which makes the spline pass through all points except the endpoints.
|
|
25404
|
+
*
|
|
25405
|
+
* `INCLUDE` case will have the spline passing through
|
|
25406
|
+
* all points, like this:
|
|
25407
|
+
*
|
|
25408
|
+
* ```js
|
|
25409
|
+
* splineProperty('ends', INCLUDE); // no need to set this, as it is the default
|
|
25410
|
+
* spline(25, 46, 93, 44, 93, 81, 35, 85);
|
|
25411
|
+
*
|
|
25412
|
+
* point(25, 46);
|
|
25413
|
+
* point(93, 44);
|
|
25414
|
+
* point(93, 81);
|
|
25415
|
+
* point(35, 85);
|
|
25416
|
+
* ```
|
|
25546
25417
|
*
|
|
25547
|
-
*
|
|
25548
|
-
* use `splineProperty('tightness', t)`, with `t` between 0 and 1,
|
|
25549
|
-
* at 0 as default.
|
|
25418
|
+
* <img src="assets/includeSpline.png"></img>
|
|
25550
25419
|
*
|
|
25551
|
-
* Spline curves are like cables that are attached to a set of points.
|
|
25552
|
-
* Adjusting tightness adjusts how tightly the cable is
|
|
25553
|
-
* attached to the points. The parameter, tightness, determines
|
|
25554
|
-
* how the curve fits to the vertex points. By default,
|
|
25555
|
-
* tightness is set to 0. Setting tightness to 1, as in
|
|
25556
|
-
* `splineProperty('tightness', 1)`, connects the curve's points
|
|
25557
|
-
* using straight lines. Values in the range from –5 to 5
|
|
25558
|
-
* deform curves while leaving them recognizable.
|
|
25559
25420
|
*
|
|
25560
|
-
*
|
|
25561
|
-
*
|
|
25562
|
-
*
|
|
25563
|
-
*
|
|
25421
|
+
* EXCLUDE case will have the spline passing through
|
|
25422
|
+
* the middle points, like this:
|
|
25423
|
+
*
|
|
25424
|
+
*
|
|
25425
|
+
* ```js
|
|
25426
|
+
* splineProperty('ends', INCLUDE);
|
|
25427
|
+
* spline(25, 46, 93, 44, 93, 81, 35, 85);
|
|
25428
|
+
*
|
|
25429
|
+
* point(25, 46);
|
|
25430
|
+
* point(93, 44);
|
|
25431
|
+
* point(93, 81);
|
|
25432
|
+
* point(35, 85);
|
|
25433
|
+
* ```
|
|
25434
|
+
*
|
|
25435
|
+
* <img src="assets/excludeSpline.png"></img>
|
|
25436
|
+
*
|
|
25437
|
+
* By default, the tightness property is set to `0`,
|
|
25438
|
+
* producing a smooth curve that passes evenly through
|
|
25439
|
+
* the vertices. Negative values make the curve looser,
|
|
25440
|
+
* while positive values make it tighter. Common values
|
|
25441
|
+
* range between -1 and 1, though values outside this
|
|
25442
|
+
* range can also be used for different effects.
|
|
25443
|
+
*
|
|
25444
|
+
* For example, To set tightness, use `splineProperty('tightness', t)`,
|
|
25445
|
+
* (default: t = 0).
|
|
25446
|
+
*
|
|
25447
|
+
* Here's the example showing negetive value of tightness,
|
|
25448
|
+
* which creates a rounder bulge:
|
|
25449
|
+
*
|
|
25450
|
+
* ```js
|
|
25451
|
+
* splineProperty('tightness', -5)
|
|
25452
|
+
* stroke(0);
|
|
25453
|
+
* strokeWeight(2);
|
|
25454
|
+
* spline(25, 46, 93, 44, 93, 81, 35, 85);
|
|
25455
|
+
* ```
|
|
25456
|
+
*
|
|
25457
|
+
* Here's the example showing positive value of tightness,
|
|
25458
|
+
* which makes the curve tighter and more angular:
|
|
25459
|
+
*
|
|
25460
|
+
* ```js
|
|
25461
|
+
* splineProperty('tightness', 5)
|
|
25462
|
+
* stroke(0);
|
|
25463
|
+
* strokeWeight(2);
|
|
25464
|
+
* spline(25, 46, 93, 44, 93, 81, 35, 85);
|
|
25465
|
+
* ```
|
|
25466
|
+
*
|
|
25467
|
+
* In all cases, the splines in p5.js are <a href = "https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Cardinal_spline">cardinal splines</a>.
|
|
25468
|
+
* When tightness is 0, these splines are often known as
|
|
25469
|
+
* <a href="https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Catmull%E2%80%93Rom_spline">Catmull-Rom splines</a>
|
|
25564
25470
|
*
|
|
25565
25471
|
* @method splineProperty
|
|
25566
25472
|
* @param {String} property
|
|
@@ -25570,33 +25476,111 @@ var p5 = (function () {
|
|
|
25570
25476
|
* <div>
|
|
25571
25477
|
* <code>
|
|
25572
25478
|
* // Move the mouse left and right to see the curve change.
|
|
25573
|
-
*
|
|
25479
|
+
*
|
|
25480
|
+
* let t;
|
|
25481
|
+
*
|
|
25574
25482
|
* function setup() {
|
|
25575
25483
|
* createCanvas(100, 100);
|
|
25576
|
-
*
|
|
25484
|
+
*
|
|
25577
25485
|
* }
|
|
25578
|
-
*
|
|
25486
|
+
*
|
|
25579
25487
|
* function draw() {
|
|
25580
|
-
* background(
|
|
25581
|
-
*
|
|
25582
|
-
*
|
|
25583
|
-
* let t = map(mouseX, 0, 100, -5, 5, true);
|
|
25488
|
+
* background(240);
|
|
25489
|
+
*
|
|
25490
|
+
* t = map(mouseX, 0, width, -5, 5, true);
|
|
25584
25491
|
* splineProperty('tightness', t);
|
|
25585
|
-
*
|
|
25586
|
-
* // Draw the curve.
|
|
25492
|
+
*
|
|
25587
25493
|
* noFill();
|
|
25494
|
+
* stroke(0);
|
|
25495
|
+
* strokeWeight(2);
|
|
25496
|
+
*
|
|
25588
25497
|
* beginShape();
|
|
25589
25498
|
* splineVertex(10, 26);
|
|
25590
|
-
* splineVertex(10, 26);
|
|
25591
25499
|
* splineVertex(83, 24);
|
|
25500
|
+
*
|
|
25592
25501
|
* splineVertex(83, 61);
|
|
25593
25502
|
* splineVertex(25, 65);
|
|
25594
|
-
* splineVertex(25, 65);
|
|
25595
25503
|
* endShape();
|
|
25504
|
+
*
|
|
25505
|
+
* push();
|
|
25506
|
+
* strokeWeight(5);
|
|
25507
|
+
* point(10, 26);
|
|
25508
|
+
* point(83, 24);
|
|
25509
|
+
* point(83, 61);
|
|
25510
|
+
* point(25, 65);
|
|
25511
|
+
* pop();
|
|
25512
|
+
*
|
|
25513
|
+
* fill(0);
|
|
25514
|
+
* noStroke();
|
|
25515
|
+
* textSize(10);
|
|
25516
|
+
* text(`tightness: ${round(t, 1)}`, 15, 90);
|
|
25517
|
+
* describe('A black spline forms a sideways U shape through four points. The spline passes through the points more loosely as the mouse moves left of center (negative tightness), and more tightly as it moves right of center (positive tightness). The tightness is displayed at the bottom.');
|
|
25518
|
+
* }
|
|
25519
|
+
* </code>
|
|
25520
|
+
* </div>
|
|
25521
|
+
*
|
|
25522
|
+
* @example
|
|
25523
|
+
* <div>
|
|
25524
|
+
* <code>
|
|
25525
|
+
* function setup() {
|
|
25526
|
+
* createCanvas(360, 140);
|
|
25527
|
+
* background(240);
|
|
25528
|
+
* noFill();
|
|
25529
|
+
*
|
|
25530
|
+
* // Right panel: ends = INCLUDE (all spans).
|
|
25531
|
+
* push();
|
|
25532
|
+
* translate(10, 10);
|
|
25533
|
+
* stroke(220);
|
|
25534
|
+
* rect(0, 0, 160, 120);
|
|
25535
|
+
* fill(30);
|
|
25536
|
+
* textSize(11);
|
|
25537
|
+
* text('ends: INCLUDE (all spans)', 8, 16);
|
|
25538
|
+
* noFill();
|
|
25539
|
+
*
|
|
25540
|
+
* splineProperty('ends', INCLUDE);
|
|
25541
|
+
* stroke(0);
|
|
25542
|
+
* strokeWeight(2);
|
|
25543
|
+
* spline(25, 46, 93, 44, 93, 81, 35, 85);
|
|
25544
|
+
*
|
|
25545
|
+
* // vertices
|
|
25546
|
+
* strokeWeight(5);
|
|
25547
|
+
* stroke(0);
|
|
25548
|
+
* point(25, 46);
|
|
25549
|
+
* point(93, 44);
|
|
25550
|
+
* point(93, 81);
|
|
25551
|
+
* point(35, 85);
|
|
25552
|
+
* pop();
|
|
25553
|
+
*
|
|
25554
|
+
* // Right panel: ends = EXCLUDE (middle only).
|
|
25555
|
+
* push();
|
|
25556
|
+
* translate(190, 10);
|
|
25557
|
+
* stroke(220);
|
|
25558
|
+
* rect(0, 0, 160, 120);
|
|
25559
|
+
* noStroke();
|
|
25560
|
+
* fill(30);
|
|
25561
|
+
* text('ends: EXCLUDE ', 18, 16);
|
|
25562
|
+
* noFill();
|
|
25563
|
+
*
|
|
25564
|
+
* splineProperty('ends', EXCLUDE);
|
|
25565
|
+
* stroke(0);
|
|
25566
|
+
* strokeWeight(2);
|
|
25567
|
+
* spline(25, 46, 93, 44, 93, 81, 35, 85);
|
|
25568
|
+
*
|
|
25569
|
+
* // vertices
|
|
25570
|
+
* strokeWeight(5);
|
|
25571
|
+
* stroke(0);
|
|
25572
|
+
* point(25, 46);
|
|
25573
|
+
* point(93, 44);
|
|
25574
|
+
* point(93, 81);
|
|
25575
|
+
* point(35, 85);
|
|
25576
|
+
* pop();
|
|
25577
|
+
*
|
|
25578
|
+
* describe('Left panel shows spline with ends INCLUDE (three spans). Right panel shows EXCLUDE (only the middle span). Four black points mark the vertices.');
|
|
25596
25579
|
* }
|
|
25597
25580
|
* </code>
|
|
25598
25581
|
* </div>
|
|
25599
25582
|
*/
|
|
25583
|
+
|
|
25600
25584
|
/**
|
|
25601
25585
|
* @method splineProperty
|
|
25602
25586
|
* @param {String} property
|
|
@@ -30446,7 +30430,7 @@ var p5 = (function () {
|
|
|
30446
30430
|
* Bézier curves can form shapes and curves that slope gently. They're defined
|
|
30447
30431
|
* by two anchor points and two control points. Bézier curves provide more
|
|
30448
30432
|
* control than the spline curves created with the
|
|
30449
|
-
* <a href="#/p5/
|
|
30433
|
+
* <a href="#/p5/spline">spline()</a> function.
|
|
30450
30434
|
*
|
|
30451
30435
|
* The first two parameters, `x1` and `y1`, set the first anchor point. The
|
|
30452
30436
|
* first anchor point is where the curve starts.
|
|
@@ -30896,38 +30880,53 @@ var p5 = (function () {
|
|
|
30896
30880
|
|
|
30897
30881
|
/**
|
|
30898
30882
|
* Draws a curve using a Catmull-Rom spline.
|
|
30899
|
-
*
|
|
30883
|
+
*
|
|
30900
30884
|
* Spline curves can form shapes and curves that slope gently. They’re like
|
|
30901
|
-
* cables that are attached to a set of points.
|
|
30902
|
-
*
|
|
30903
|
-
*
|
|
30904
|
-
*
|
|
30905
|
-
*
|
|
30906
|
-
*
|
|
30907
|
-
* The next four parameters, `x2`, `y2`, `x3`, and `y3`, set the two anchor
|
|
30908
|
-
* points. The anchor points are the start and end points of the curve’s
|
|
30909
|
-
* visible segment.
|
|
30910
|
-
*
|
|
30911
|
-
* The seventh and eighth parameters, `x4` and `y4`, set the last control
|
|
30912
|
-
* point. This point isn’t drawn and can be thought of as the curve’s ending
|
|
30913
|
-
* point.
|
|
30885
|
+
* cables that are attached to a set of points. By default (`ends: INCLUDE`),
|
|
30886
|
+
* the curve passes through all four points you provide, in order
|
|
30887
|
+
* `p0(x1,y1)` -> `p1(x2,y2)` -> `p2(x3,y3)` -> `p3(x4,y4)`. Think of them as
|
|
30888
|
+
* points on a curve. If you switch to `ends: EXCLUDE`, p0 and p3 act
|
|
30889
|
+
* like control points and only the middle span `p1->p2` is drawn.
|
|
30914
30890
|
*
|
|
30915
30891
|
* Spline curves can also be drawn in 3D using WebGL mode. The 3D version of
|
|
30916
30892
|
* `spline()` has twelve arguments because each point has x-, y-, and
|
|
30917
30893
|
* z-coordinates.
|
|
30918
30894
|
*
|
|
30919
30895
|
* @method spline
|
|
30920
|
-
* @param {Number} x1 x-coordinate of
|
|
30921
|
-
* @param {Number} y1 y-coordinate of
|
|
30922
|
-
* @param {Number} x2 x-coordinate of
|
|
30923
|
-
* @param {Number} y2 y-coordinate of
|
|
30924
|
-
* @param {Number} x3 x-coordinate of
|
|
30925
|
-
* @param {Number} y3 y-coordinate of
|
|
30926
|
-
* @param {Number} x4 x-coordinate of
|
|
30927
|
-
* @param {Number} y4 y-coordinate of
|
|
30896
|
+
* @param {Number} x1 x-coordinate of point p0.
|
|
30897
|
+
* @param {Number} y1 y-coordinate of point p0.
|
|
30898
|
+
* @param {Number} x2 x-coordinate of point p1.
|
|
30899
|
+
* @param {Number} y2 y-coordinate of point p1.
|
|
30900
|
+
* @param {Number} x3 x-coordinate of point p2.
|
|
30901
|
+
* @param {Number} y3 y-coordinate of point p2.
|
|
30902
|
+
* @param {Number} x4 x-coordinate of point p3.
|
|
30903
|
+
* @param {Number} y4 y-coordinate of point p3.
|
|
30928
30904
|
* @chainable
|
|
30929
30905
|
*
|
|
30930
30906
|
* @example
|
|
30907
|
+
*
|
|
30908
|
+
* <div>
|
|
30909
|
+
* <code>
|
|
30910
|
+
* function setup() {
|
|
30911
|
+
* createCanvas(200, 200);
|
|
30912
|
+
* background(240);
|
|
30913
|
+
* noFill();
|
|
30914
|
+
*
|
|
30915
|
+
* stroke(0);
|
|
30916
|
+
* strokeWeight(2);
|
|
30917
|
+
* spline(40, 60, 100, 40, 120, 120, 60, 140);
|
|
30918
|
+
*
|
|
30919
|
+
* strokeWeight(5);
|
|
30920
|
+
* point(40, 60);
|
|
30921
|
+
* point(100, 40);
|
|
30922
|
+
* point(120, 120);
|
|
30923
|
+
* point(60, 140);
|
|
30924
|
+
*
|
|
30925
|
+
* describe('A black spline passes smoothly through four points');
|
|
30926
|
+
* }
|
|
30927
|
+
* </code>
|
|
30928
|
+
* </div>
|
|
30929
|
+
*
|
|
30931
30930
|
* <div>
|
|
30932
30931
|
* <code>
|
|
30933
30932
|
* function setup() {
|
|
@@ -30935,24 +30934,27 @@ var p5 = (function () {
|
|
|
30935
30934
|
*
|
|
30936
30935
|
* background(200);
|
|
30937
30936
|
*
|
|
30937
|
+
* // Exclude the ends—skip the outer spans (p0→p1 and p2→p3) so only the middle span (p1→p2) is drawn.
|
|
30938
|
+
* splineProperty('ends', EXCLUDE);
|
|
30939
|
+
*
|
|
30938
30940
|
* // Draw a black spline curve.
|
|
30939
30941
|
* noFill();
|
|
30940
30942
|
* strokeWeight(1);
|
|
30941
30943
|
* stroke(0);
|
|
30942
30944
|
* spline(5, 26, 73, 24, 73, 61, 15, 65);
|
|
30943
30945
|
*
|
|
30944
|
-
* // Draw red spline curves from the
|
|
30946
|
+
* // Draw red spline curves from the points.
|
|
30945
30947
|
* stroke(255, 0, 0);
|
|
30946
30948
|
* spline(5, 26, 5, 26, 73, 24, 73, 61);
|
|
30947
30949
|
* spline(73, 24, 73, 61, 15, 65, 15, 65);
|
|
30948
30950
|
*
|
|
30949
|
-
* // Draw the
|
|
30951
|
+
* // Draw the points in black.
|
|
30950
30952
|
* strokeWeight(5);
|
|
30951
30953
|
* stroke(0);
|
|
30952
30954
|
* point(73, 24);
|
|
30953
30955
|
* point(73, 61);
|
|
30954
30956
|
*
|
|
30955
|
-
* // Draw the
|
|
30957
|
+
* // Draw the points in red.
|
|
30956
30958
|
* stroke(255, 0, 0);
|
|
30957
30959
|
* point(5, 26);
|
|
30958
30960
|
* point(15, 65);
|
|
@@ -30980,14 +30982,17 @@ var p5 = (function () {
|
|
|
30980
30982
|
*
|
|
30981
30983
|
* function draw() {
|
|
30982
30984
|
* background(200);
|
|
30983
|
-
*
|
|
30985
|
+
*
|
|
30986
|
+
* // Exclude the ends—skip the outer spans (p0→p1 and p2→p3) so only the middle span (p1→p2) is drawn.
|
|
30987
|
+
* splineProperty('ends', EXCLUDE);
|
|
30988
|
+
*
|
|
30984
30989
|
* // Draw a black spline curve.
|
|
30985
30990
|
* noFill();
|
|
30986
30991
|
* strokeWeight(1);
|
|
30987
30992
|
* stroke(0);
|
|
30988
30993
|
* spline(x1, y1, 73, 24, 73, 61, 15, 65);
|
|
30989
30994
|
*
|
|
30990
|
-
* // Draw red spline curves from the
|
|
30995
|
+
* // Draw red spline curves from the points.
|
|
30991
30996
|
* stroke(255, 0, 0);
|
|
30992
30997
|
* spline(x1, y1, x1, y1, 73, 24, 73, 61);
|
|
30993
30998
|
* spline(73, 24, 73, 61, 15, 65, 15, 65);
|
|
@@ -30998,25 +31003,25 @@ var p5 = (function () {
|
|
|
30998
31003
|
* point(73, 24);
|
|
30999
31004
|
* point(73, 61);
|
|
31000
31005
|
*
|
|
31001
|
-
* // Draw the
|
|
31006
|
+
* // Draw the points in red.
|
|
31002
31007
|
* stroke(255, 0, 0);
|
|
31003
31008
|
* point(x1, y1);
|
|
31004
31009
|
* point(15, 65);
|
|
31005
31010
|
* }
|
|
31006
31011
|
*
|
|
31007
|
-
* // Start changing the first
|
|
31012
|
+
* // Start changing the first point if the user clicks near it.
|
|
31008
31013
|
* function mousePressed() {
|
|
31009
31014
|
* if (dist(mouseX, mouseY, x1, y1) < 20) {
|
|
31010
31015
|
* isChanging = true;
|
|
31011
31016
|
* }
|
|
31012
31017
|
* }
|
|
31013
31018
|
*
|
|
31014
|
-
* // Stop changing the first
|
|
31019
|
+
* // Stop changing the first point when the user releases the mouse.
|
|
31015
31020
|
* function mouseReleased() {
|
|
31016
31021
|
* isChanging = false;
|
|
31017
31022
|
* }
|
|
31018
31023
|
*
|
|
31019
|
-
* // Update the first
|
|
31024
|
+
* // Update the first point while the user drags the mouse.
|
|
31020
31025
|
* function mouseDragged() {
|
|
31021
31026
|
* if (isChanging === true) {
|
|
31022
31027
|
* x1 = mouseX;
|
|
@@ -31032,7 +31037,10 @@ var p5 = (function () {
|
|
|
31032
31037
|
* createCanvas(100, 100);
|
|
31033
31038
|
*
|
|
31034
31039
|
* background('skyblue');
|
|
31035
|
-
*
|
|
31040
|
+
*
|
|
31041
|
+
* // Exclude the ends—skip the outer spans (p0→p1 and p2→p3) so only the middle span (p1→p2) is drawn.
|
|
31042
|
+
* splineProperty('ends', EXCLUDE);
|
|
31043
|
+
*
|
|
31036
31044
|
* // Draw the red balloon.
|
|
31037
31045
|
* fill('red');
|
|
31038
31046
|
* spline(-150, 275, 50, 60, 50, 60, 250, 275);
|
|
@@ -31055,7 +31063,10 @@ var p5 = (function () {
|
|
|
31055
31063
|
*
|
|
31056
31064
|
* function draw() {
|
|
31057
31065
|
* background('skyblue');
|
|
31058
|
-
*
|
|
31066
|
+
*
|
|
31067
|
+
* // Exclude the ends—skip the outer spans (p0→p1 and p2→p3) so only the middle span (p1→p2) is drawn.
|
|
31068
|
+
* splineProperty('ends', EXCLUDE);
|
|
31069
|
+
*
|
|
31059
31070
|
* // Rotate around the y-axis.
|
|
31060
31071
|
* rotateY(frameCount * 0.01);
|
|
31061
31072
|
*
|
|
@@ -31074,16 +31085,16 @@ var p5 = (function () {
|
|
|
31074
31085
|
* @method spline
|
|
31075
31086
|
* @param {Number} x1
|
|
31076
31087
|
* @param {Number} y1
|
|
31077
|
-
* @param {Number} z1 z-coordinate of
|
|
31088
|
+
* @param {Number} z1 z-coordinate of point p0.
|
|
31078
31089
|
* @param {Number} x2
|
|
31079
31090
|
* @param {Number} y2
|
|
31080
|
-
* @param {Number} z2 z-coordinate of
|
|
31091
|
+
* @param {Number} z2 z-coordinate of point p1.
|
|
31081
31092
|
* @param {Number} x3
|
|
31082
31093
|
* @param {Number} y3
|
|
31083
|
-
* @param {Number} z3 z-coordinate of
|
|
31094
|
+
* @param {Number} z3 z-coordinate of point p2.
|
|
31084
31095
|
* @param {Number} x4
|
|
31085
31096
|
* @param {Number} y4
|
|
31086
|
-
* @param {Number} z4 z-coordinate of
|
|
31097
|
+
* @param {Number} z4 z-coordinate of point p3.
|
|
31087
31098
|
* @chainable
|
|
31088
31099
|
*/
|
|
31089
31100
|
fn.spline = function(...args) {
|
|
@@ -31098,30 +31109,30 @@ var p5 = (function () {
|
|
|
31098
31109
|
/**
|
|
31099
31110
|
* Calculates coordinates along a spline curve using interpolation.
|
|
31100
31111
|
*
|
|
31101
|
-
* `splinePoint()` calculates coordinates along a spline curve using
|
|
31102
|
-
*
|
|
31112
|
+
* `splinePoint()` calculates coordinates along a spline curve using four
|
|
31113
|
+
* points p0, p1, p2, p3. It expects points in the same order as the
|
|
31103
31114
|
* <a href="#/p5/spline">spline()</a> function. `splinePoint()` works one axis
|
|
31104
|
-
* at a time. Passing the
|
|
31105
|
-
* calculate the x-coordinate of a point on the curve. Passing the
|
|
31106
|
-
*
|
|
31115
|
+
* at a time. Passing the points' x-coordinates will
|
|
31116
|
+
* calculate the x-coordinate of a point on the curve. Passing the
|
|
31117
|
+
* points' y-coordinates will calculate the y-coordinate of a point on
|
|
31107
31118
|
* the curve.
|
|
31108
31119
|
*
|
|
31109
|
-
* The first parameter, `a`, is the coordinate of
|
|
31120
|
+
* The first parameter, `a`, is the coordinate of point p0.
|
|
31110
31121
|
*
|
|
31111
|
-
* The second and third parameters, `b` and `c`, are the coordinates of
|
|
31112
|
-
*
|
|
31122
|
+
* The second and third parameters, `b` and `c`, are the coordinates of
|
|
31123
|
+
* points p1 and p2.
|
|
31113
31124
|
*
|
|
31114
|
-
* The fourth parameter, `d`, is the coordinate of
|
|
31125
|
+
* The fourth parameter, `d`, is the coordinate of point p3.
|
|
31115
31126
|
*
|
|
31116
|
-
* The fifth parameter, `t`, is the amount to interpolate along the
|
|
31117
|
-
*
|
|
31127
|
+
* The fifth parameter, `t`, is the amount to interpolate along the span
|
|
31128
|
+
* from p1 to p2. `t = 0` is p1, `t = 1` is p2, and `t = 0.5` is halfway
|
|
31118
31129
|
* between them.
|
|
31119
31130
|
*
|
|
31120
31131
|
* @method splinePoint
|
|
31121
|
-
* @param {Number} a coordinate of
|
|
31122
|
-
* @param {Number} b coordinate of
|
|
31123
|
-
* @param {Number} c coordinate of
|
|
31124
|
-
* @param {Number} d coordinate of
|
|
31132
|
+
* @param {Number} a coordinate of point p0.
|
|
31133
|
+
* @param {Number} b coordinate of point p1.
|
|
31134
|
+
* @param {Number} c coordinate of point p2.
|
|
31135
|
+
* @param {Number} d coordinate of point p3.
|
|
31125
31136
|
* @param {Number} t amount to interpolate between 0 and 1.
|
|
31126
31137
|
* @return {Number} coordinate of a point on the curve.
|
|
31127
31138
|
*
|
|
@@ -31133,7 +31144,8 @@ var p5 = (function () {
|
|
|
31133
31144
|
*
|
|
31134
31145
|
* background(200);
|
|
31135
31146
|
*
|
|
31136
|
-
*
|
|
31147
|
+
*
|
|
31148
|
+
* // Set the coordinates for the curve's four points (p0, p1, p2, p3).
|
|
31137
31149
|
* let x1 = 5;
|
|
31138
31150
|
* let y1 = 26;
|
|
31139
31151
|
* let x2 = 73;
|
|
@@ -31181,7 +31193,7 @@ var p5 = (function () {
|
|
|
31181
31193
|
* function draw() {
|
|
31182
31194
|
* background(200);
|
|
31183
31195
|
*
|
|
31184
|
-
* // Set the coordinates for the curve's
|
|
31196
|
+
* // Set the coordinates for the curve's four points (p0, p1, p2, p3).
|
|
31185
31197
|
* let x1 = 5;
|
|
31186
31198
|
* let y1 = 26;
|
|
31187
31199
|
* let x2 = 73;
|
|
@@ -31207,6 +31219,7 @@ var p5 = (function () {
|
|
|
31207
31219
|
* </code>
|
|
31208
31220
|
* </div>
|
|
31209
31221
|
*/
|
|
31222
|
+
|
|
31210
31223
|
fn.splinePoint = function(a, b, c, d, t) {
|
|
31211
31224
|
const s = this._renderer.states.splineProperties.tightness,
|
|
31212
31225
|
t3 = t * t * t,
|
|
@@ -31224,30 +31237,27 @@ var p5 = (function () {
|
|
|
31224
31237
|
* Tangent lines skim the surface of a curve. A tangent line's slope equals
|
|
31225
31238
|
* the curve's slope at the point where it intersects.
|
|
31226
31239
|
*
|
|
31227
|
-
* `splineTangent()` calculates coordinates along a tangent line using
|
|
31228
|
-
*
|
|
31229
|
-
*
|
|
31230
|
-
*
|
|
31231
|
-
*
|
|
31232
|
-
*
|
|
31233
|
-
* the y-coordinate of a point on the tangent line.
|
|
31240
|
+
* `splineTangent()` calculates coordinates along a tangent line using four
|
|
31241
|
+
* points p0, p1, p2, p3. It expects points in the same order as the
|
|
31242
|
+
* <a href="#/p5/spline">spline()</a> function. `splineTangent()` works one
|
|
31243
|
+
* axis at a time. Passing the points' x-coordinates returns the x-component of
|
|
31244
|
+
* the tangent vector; passing the points' y-coordinates returns the y-component.
|
|
31245
|
+
* The first parameter, `a`, is the coordinate of point p0.
|
|
31234
31246
|
*
|
|
31235
|
-
* The
|
|
31236
|
-
*
|
|
31237
|
-
* The second and third parameters, `b` and `c`, are the coordinates of the
|
|
31238
|
-
* anchor points.
|
|
31247
|
+
* The second and third parameters, `b` and `c`, are the coordinates of
|
|
31248
|
+
* points p1 and p2.
|
|
31239
31249
|
*
|
|
31240
|
-
* The fourth parameter, `d`, is the coordinate of
|
|
31250
|
+
* The fourth parameter, `d`, is the coordinate of point p3.
|
|
31241
31251
|
*
|
|
31242
|
-
* The fifth parameter, `t`, is the amount to interpolate along the
|
|
31243
|
-
*
|
|
31252
|
+
* The fifth parameter, `t`, is the amount to interpolate along the span
|
|
31253
|
+
* from p1 to p2. `t = 0` is p1, `t = 1` is p2, and `t = 0.5` is halfway
|
|
31244
31254
|
* between them.
|
|
31245
31255
|
*
|
|
31246
31256
|
* @method splineTangent
|
|
31247
|
-
* @param {Number} a coordinate of
|
|
31248
|
-
* @param {Number} b coordinate of
|
|
31249
|
-
* @param {Number} c coordinate of
|
|
31250
|
-
* @param {Number} d coordinate of
|
|
31257
|
+
* @param {Number} a coordinate of point p0.
|
|
31258
|
+
* @param {Number} b coordinate of point p1.
|
|
31259
|
+
* @param {Number} c coordinate of point p2.
|
|
31260
|
+
* @param {Number} d coordinate of point p3.
|
|
31251
31261
|
* @param {Number} t amount to interpolate between 0 and 1.
|
|
31252
31262
|
* @return {Number} coordinate of a point on the tangent line.
|
|
31253
31263
|
*
|
|
@@ -31255,11 +31265,54 @@ var p5 = (function () {
|
|
|
31255
31265
|
* <div>
|
|
31256
31266
|
* <code>
|
|
31257
31267
|
* function setup() {
|
|
31268
|
+
* createCanvas(120, 120);
|
|
31269
|
+
* 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.');
|
|
31270
|
+
* }
|
|
31271
|
+
*
|
|
31272
|
+
* function draw() {
|
|
31273
|
+
* background(240);
|
|
31274
|
+
*
|
|
31275
|
+
* const x1 = 15, y1 = 40;
|
|
31276
|
+
* const x2 = 90, y2 = 25;
|
|
31277
|
+
* const x3 = 95, y3 = 95;
|
|
31278
|
+
* const x4 = 30, y4 = 110;
|
|
31279
|
+
*
|
|
31280
|
+
* noFill();
|
|
31281
|
+
* stroke(0);
|
|
31282
|
+
* strokeWeight(2);
|
|
31283
|
+
* spline(x1, y1, x2, y2, x3, y3, x4, y4);
|
|
31284
|
+
*
|
|
31285
|
+
* const t = 0.5 + 0.5 * sin(frameCount * 0.03);
|
|
31286
|
+
*
|
|
31287
|
+
* const px = splinePoint(x1, x2, x3, x4, t);
|
|
31288
|
+
* const py = splinePoint(y1, y2, y3, y4, t);
|
|
31289
|
+
*
|
|
31290
|
+
* let tx = splineTangent(x1, x2, x3, x4, t);
|
|
31291
|
+
* let ty = splineTangent(y1, y2, y3, y4, t);
|
|
31292
|
+
*
|
|
31293
|
+
* const m = Math.hypot(tx, ty) || 1;
|
|
31294
|
+
* tx = (tx / m) * 16;
|
|
31295
|
+
* ty = (ty / m) * 16;
|
|
31296
|
+
*
|
|
31297
|
+
* stroke(0);
|
|
31298
|
+
* strokeWeight(2);
|
|
31299
|
+
* line(px, py, px + tx, py + ty);
|
|
31300
|
+
*
|
|
31301
|
+
* noStroke();
|
|
31302
|
+
* fill('red');
|
|
31303
|
+
* circle(px, py, 7);
|
|
31304
|
+
* }
|
|
31305
|
+
* </code>
|
|
31306
|
+
* </div>
|
|
31307
|
+
*
|
|
31308
|
+
* <div>
|
|
31309
|
+
* <code>
|
|
31310
|
+
* function setup() {
|
|
31258
31311
|
* createCanvas(100, 100);
|
|
31259
31312
|
*
|
|
31260
31313
|
* background(200);
|
|
31261
31314
|
*
|
|
31262
|
-
* // Set the coordinates for the curve's
|
|
31315
|
+
* // Set the coordinates for the curve's four points (p0, p1, p2, p3).
|
|
31263
31316
|
* let x1 = 5;
|
|
31264
31317
|
* let y1 = 26;
|
|
31265
31318
|
* let x2 = 73;
|
|
@@ -53770,7 +53823,7 @@ var p5 = (function () {
|
|
|
53770
53823
|
|
|
53771
53824
|
_prepareUserAttributes(geometry, shader) {
|
|
53772
53825
|
for (const buff of this.buffers.user) {
|
|
53773
|
-
if (!this._pInst.constructor.
|
|
53826
|
+
if (!this._pInst.constructor.disableFriendlyErrors) {
|
|
53774
53827
|
// Check for the right data size
|
|
53775
53828
|
const prop = geometry.userVertexProperties[buff.attr];
|
|
53776
53829
|
if (prop) {
|
|
@@ -72271,7 +72324,7 @@ var p5 = (function () {
|
|
|
72271
72324
|
if (!this.ingredients.shapes[f]) {
|
|
72272
72325
|
this.ingredients.shapes[f] = [include];
|
|
72273
72326
|
//if other shapes of this type have been created
|
|
72274
|
-
} else
|
|
72327
|
+
} else {
|
|
72275
72328
|
//for every shape of this type
|
|
72276
72329
|
for (let y in this.ingredients.shapes[f]) {
|
|
72277
72330
|
//compare it with current shape and if it already exists make add false
|
|
@@ -128184,7 +128237,11 @@ var p5 = (function () {
|
|
|
128184
128237
|
const transpiledSource = escodegen.generate(ast);
|
|
128185
128238
|
const scopeKeys = Object.keys(scope);
|
|
128186
128239
|
const internalGeneratorFunction = new Function(
|
|
128187
|
-
|
|
128240
|
+
// Create a parameter called __p5, not just p5, because users of instance mode
|
|
128241
|
+
// may pass in a variable called p5 as a scope variable. If we rely on a variable called
|
|
128242
|
+
// p5, then the scope variable called p5 might accidentally override internal function
|
|
128243
|
+
// calls to p5 static methods.
|
|
128244
|
+
'__p5',
|
|
128188
128245
|
...scopeKeys,
|
|
128189
128246
|
transpiledSource
|
|
128190
128247
|
.slice(
|
|
@@ -128249,7 +128306,7 @@ var p5 = (function () {
|
|
|
128249
128306
|
node.type = 'CallExpression';
|
|
128250
128307
|
node.callee = {
|
|
128251
128308
|
type: 'Identifier',
|
|
128252
|
-
name: '
|
|
128309
|
+
name: '__p5.unaryNode',
|
|
128253
128310
|
};
|
|
128254
128311
|
node.arguments = [node.argument, signNode];
|
|
128255
128312
|
};
|
|
@@ -128272,7 +128329,7 @@ var p5 = (function () {
|
|
|
128272
128329
|
type: 'CallExpression',
|
|
128273
128330
|
callee: {
|
|
128274
128331
|
type: 'Identifier',
|
|
128275
|
-
name: '
|
|
128332
|
+
name: '__p5.unaryNode'
|
|
128276
128333
|
},
|
|
128277
128334
|
arguments: [node.argument.object, signNode],
|
|
128278
128335
|
};
|
|
@@ -128337,7 +128394,7 @@ var p5 = (function () {
|
|
|
128337
128394
|
node.type = 'CallExpression';
|
|
128338
128395
|
node.callee = {
|
|
128339
128396
|
type: 'Identifier',
|
|
128340
|
-
name: '
|
|
128397
|
+
name: '__p5.dynamicNode',
|
|
128341
128398
|
};
|
|
128342
128399
|
node.arguments = [original];
|
|
128343
128400
|
},
|
|
@@ -128391,7 +128448,7 @@ var p5 = (function () {
|
|
|
128391
128448
|
type: 'CallExpression',
|
|
128392
128449
|
callee: {
|
|
128393
128450
|
type: 'Identifier',
|
|
128394
|
-
name: '
|
|
128451
|
+
name: '__p5.dynamicNode',
|
|
128395
128452
|
},
|
|
128396
128453
|
arguments: [node.left]
|
|
128397
128454
|
};
|
|
@@ -129753,7 +129810,6 @@ var p5 = (function () {
|
|
|
129753
129810
|
],
|
|
129754
129811
|
'sqrt': { args: ['genType'], returnType: 'genType', isp5Function: true},
|
|
129755
129812
|
'step': { args: ['genType', 'genType'], returnType: 'genType', isp5Function: false},
|
|
129756
|
-
'noise': { args: ['vec2'], returnType: 'float', isp5Function: false },
|
|
129757
129813
|
'trunc': { args: ['genType'], returnType: 'genType', isp5Function: false},
|
|
129758
129814
|
|
|
129759
129815
|
////////// Vector //////////
|
|
@@ -129820,7 +129876,7 @@ var p5 = (function () {
|
|
|
129820
129876
|
} else {
|
|
129821
129877
|
nodeArgs = args;
|
|
129822
129878
|
}
|
|
129823
|
-
|
|
129879
|
+
|
|
129824
129880
|
return fnNodeConstructor('noise', nodeArgs, {
|
|
129825
129881
|
args: ['vec2'],
|
|
129826
129882
|
returnType: 'float'
|