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
|
@@ -60,49 +60,44 @@ function bezierOrder(order: number): void;
|
|
|
60
60
|
function bezierOrder(): number;
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
|
-
*
|
|
64
|
-
* it creates
|
|
65
|
-
*
|
|
66
|
-
* between the
|
|
63
|
+
* Connects points with a smooth curve (a spline).`splineVertex()` adds a curved segment to custom shapes.
|
|
64
|
+
* The curve it creates follows the same rules as the ones
|
|
65
|
+
* made with the spline() function.
|
|
66
|
+
* `splineVertex()` must be called between the
|
|
67
|
+
* beginShape() and
|
|
67
68
|
* endShape() functions.Spline curves can form shapes and curves that slope gently. They’re like
|
|
68
|
-
* cables that are attached to a set of points.
|
|
69
|
-
*
|
|
70
|
-
* least four times between
|
|
69
|
+
* cables that are attached to a set of points. `splineVertex()` draws a smooth
|
|
70
|
+
* curve through the points you give it.
|
|
71
71
|
* beginShape() and
|
|
72
|
-
* endShape() in order to draw a curve
|
|
73
|
-
*
|
|
74
|
-
* // Add the first control point.
|
|
75
|
-
* splineVertex(84, 91);
|
|
72
|
+
* endShape() in order to draw a curve:If you provide three points, the spline will pass through them.
|
|
73
|
+
* It works the same way with any number of points.`beginShape();
|
|
76
74
|
*
|
|
77
|
-
* // Add the
|
|
78
|
-
* splineVertex(
|
|
79
|
-
* splineVertex(21, 17);
|
|
75
|
+
* // Add the first point.
|
|
76
|
+
* splineVertex(25, 80);
|
|
80
77
|
*
|
|
81
|
-
* // Add the second
|
|
82
|
-
* splineVertex(
|
|
78
|
+
* // Add the second point.
|
|
79
|
+
* splineVertex(20, 30);
|
|
83
80
|
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
* between the control and anchor points can be drawn by calling
|
|
87
|
-
* `splineVertex()` with the coordinates of the control points:`beginShape();
|
|
81
|
+
* // Add the last point.
|
|
82
|
+
* splineVertex(85, 60);
|
|
88
83
|
*
|
|
89
|
-
*
|
|
90
|
-
* splineVertex(84, 91);
|
|
91
|
-
* splineVertex(84, 91);
|
|
84
|
+
* endShape();`Passing in `CLOSE` to `endShape()` closes the spline smoothly.`beginShape();
|
|
92
85
|
*
|
|
93
|
-
* // Add the
|
|
94
|
-
* splineVertex(
|
|
95
|
-
* splineVertex(21, 17);
|
|
86
|
+
* // Add the first point.
|
|
87
|
+
* splineVertex(25, 80);
|
|
96
88
|
*
|
|
97
|
-
* // Add the second
|
|
98
|
-
* splineVertex(
|
|
89
|
+
* // Add the second point.
|
|
90
|
+
* splineVertex(20, 30);
|
|
99
91
|
*
|
|
100
|
-
* //
|
|
101
|
-
*
|
|
92
|
+
* // Add the second point.
|
|
93
|
+
* splineVertex(85, 60);
|
|
102
94
|
*
|
|
103
|
-
* endShape();`
|
|
104
|
-
*
|
|
105
|
-
*
|
|
95
|
+
* endShape(CLOSE);`By default (`ends: INCLUDE`), the curve passes through
|
|
96
|
+
* all the points you add with `splineVertex()`, similar to
|
|
97
|
+
* the spline() function. To draw only
|
|
98
|
+
* the middle span p1->p2 (skipping p0->p1 and p2->p3), set
|
|
99
|
+
* `splineProperty('ends', EXCLUDE)`. You don’t need to duplicate
|
|
100
|
+
* vertices to draw those spans.Spline curves can also be drawn in 3D using WebGL mode. The 3D version of
|
|
106
101
|
* `splineVertex()` has three arguments because each point has x-, y-, and
|
|
107
102
|
* z-coordinates. By default, the vertex’s z-coordinate is set to 0.Note: `splineVertex()` won’t work when an argument is passed to
|
|
108
103
|
* beginShape().
|
|
@@ -114,45 +109,28 @@ function bezierOrder(): number;
|
|
|
114
109
|
* function setup() {
|
|
115
110
|
* createCanvas(100, 100);
|
|
116
111
|
*
|
|
117
|
-
* background(
|
|
118
|
-
*
|
|
119
|
-
* // Style the shape.
|
|
112
|
+
* background(220);
|
|
120
113
|
* noFill();
|
|
121
114
|
* strokeWeight(1);
|
|
122
115
|
*
|
|
123
|
-
* // Start drawing the shape.
|
|
124
116
|
* beginShape();
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
* splineVertex(
|
|
128
|
-
*
|
|
129
|
-
* // Add the anchor points.
|
|
130
|
-
* splineVertex(21, 17);
|
|
131
|
-
* splineVertex(68, 19);
|
|
132
|
-
*
|
|
133
|
-
* // Add the second control point.
|
|
134
|
-
* splineVertex(84, 91);
|
|
135
|
-
*
|
|
136
|
-
* // Stop drawing the shape.
|
|
117
|
+
* splineVertex(25, 80);
|
|
118
|
+
* splineVertex(20, 30);
|
|
119
|
+
* splineVertex(85, 60);
|
|
137
120
|
* endShape();
|
|
138
121
|
*
|
|
139
|
-
* // Style the anchor and control points.
|
|
140
122
|
* strokeWeight(5);
|
|
141
|
-
*
|
|
142
|
-
* // Draw the anchor points in black.
|
|
143
123
|
* stroke(0);
|
|
144
|
-
* point(21, 17);
|
|
145
|
-
* point(68, 19);
|
|
146
124
|
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
* point(
|
|
150
|
-
* point(84, 91);
|
|
125
|
+
* point(25, 80);
|
|
126
|
+
* point(20, 30);
|
|
127
|
+
* point(85, 60);
|
|
151
128
|
*
|
|
152
129
|
* describe(
|
|
153
|
-
* '
|
|
130
|
+
* 'On a gray background, a black spline passes through three marked points.'
|
|
154
131
|
* );
|
|
155
132
|
* }
|
|
133
|
+
*
|
|
156
134
|
* </code>
|
|
157
135
|
* </div>
|
|
158
136
|
*
|
|
@@ -160,204 +138,63 @@ function bezierOrder(): number;
|
|
|
160
138
|
* <code>
|
|
161
139
|
* function setup() {
|
|
162
140
|
* createCanvas(100, 100);
|
|
141
|
+
* background(220);
|
|
163
142
|
*
|
|
164
|
-
* background(200);
|
|
165
|
-
*
|
|
166
|
-
* // Style the shape.
|
|
167
|
-
* noFill();
|
|
168
|
-
* strokeWeight(1);
|
|
169
|
-
*
|
|
170
|
-
* // Start drawing the shape.
|
|
171
143
|
* beginShape();
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
* splineVertex(
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
* // Add the anchor points.
|
|
178
|
-
* splineVertex(21, 17);
|
|
179
|
-
* splineVertex(68, 19);
|
|
180
|
-
*
|
|
181
|
-
* // Add the second control point.
|
|
182
|
-
* splineVertex(84, 91);
|
|
183
|
-
*
|
|
184
|
-
* // Stop drawing the shape.
|
|
185
|
-
* endShape();
|
|
186
|
-
*
|
|
187
|
-
* // Style the anchor and control points.
|
|
188
|
-
* strokeWeight(5);
|
|
189
|
-
*
|
|
190
|
-
* // Draw the anchor points in black.
|
|
191
|
-
* stroke(0);
|
|
192
|
-
* point(21, 17);
|
|
193
|
-
* point(68, 19);
|
|
194
|
-
*
|
|
195
|
-
* // Draw the control points in red.
|
|
196
|
-
* stroke(255, 0, 0);
|
|
197
|
-
* point(32, 91);
|
|
198
|
-
* point(84, 91);
|
|
144
|
+
* splineVertex(25, 80);
|
|
145
|
+
* splineVertex(20, 30);
|
|
146
|
+
* splineVertex(85, 60);
|
|
147
|
+
* endShape(CLOSE);
|
|
199
148
|
*
|
|
200
149
|
* describe(
|
|
201
|
-
* '
|
|
150
|
+
* 'On a gray background, a closed black spline with a white interior forms a triangular shape with smooth corners.'
|
|
202
151
|
* );
|
|
203
152
|
* }
|
|
153
|
+
*
|
|
204
154
|
* </code>
|
|
205
155
|
* </div>
|
|
206
156
|
*
|
|
207
157
|
* <div>
|
|
208
158
|
* <code>
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
* // Style the shape.
|
|
215
|
-
* noFill();
|
|
216
|
-
* strokeWeight(1);
|
|
217
|
-
*
|
|
218
|
-
* // Start drawing the shape.
|
|
219
|
-
* beginShape();
|
|
220
|
-
*
|
|
221
|
-
* // Add the first control point and draw a segment to it.
|
|
222
|
-
* splineVertex(32, 91);
|
|
223
|
-
* splineVertex(32, 91);
|
|
224
|
-
*
|
|
225
|
-
* // Add the anchor points.
|
|
226
|
-
* splineVertex(21, 17);
|
|
227
|
-
* splineVertex(68, 19);
|
|
228
|
-
*
|
|
229
|
-
* // Add the second control point and draw a segment to it.
|
|
230
|
-
* splineVertex(84, 91);
|
|
231
|
-
* splineVertex(84, 91);
|
|
232
|
-
*
|
|
233
|
-
* // Stop drawing the shape.
|
|
234
|
-
* endShape();
|
|
235
|
-
*
|
|
236
|
-
* // Style the anchor and control points.
|
|
237
|
-
* strokeWeight(5);
|
|
238
|
-
*
|
|
239
|
-
* // Draw the anchor points in black.
|
|
240
|
-
* stroke(0);
|
|
241
|
-
* point(21, 17);
|
|
242
|
-
* point(68, 19);
|
|
243
|
-
*
|
|
244
|
-
* // Draw the control points in red.
|
|
245
|
-
* stroke(255, 0, 0);
|
|
246
|
-
* point(32, 91);
|
|
247
|
-
* point(84, 91);
|
|
159
|
+
* let ringInnerRadius, ringWidth;
|
|
160
|
+
* let radius, dRadius;
|
|
161
|
+
* let theta, dTheta;
|
|
162
|
+
* let time, dTime;
|
|
163
|
+
* let vertexCount, unit, offset;
|
|
248
164
|
*
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
* );
|
|
252
|
-
* }
|
|
253
|
-
* </code>
|
|
254
|
-
* </div>
|
|
165
|
+
* function setup() {
|
|
166
|
+
* createCanvas(400, 400);
|
|
255
167
|
*
|
|
256
|
-
*
|
|
257
|
-
*
|
|
258
|
-
*
|
|
259
|
-
*
|
|
168
|
+
* vertexCount = 15;
|
|
169
|
+
* unit = createVector(1, 0);
|
|
170
|
+
* dTheta = TAU / vertexCount;
|
|
171
|
+
* dTime = 0.004;
|
|
260
172
|
*
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
* let isChanging = false;
|
|
173
|
+
* ringInnerRadius = 25;
|
|
174
|
+
* ringWidth = 5 * ringInnerRadius;
|
|
264
175
|
*
|
|
265
|
-
*
|
|
266
|
-
* createCanvas(100, 100);
|
|
176
|
+
* offset = width;
|
|
267
177
|
*
|
|
268
178
|
* describe(
|
|
269
|
-
* 'A
|
|
179
|
+
* 'A white blob with a black outline changes its shape over time.'
|
|
270
180
|
* );
|
|
271
181
|
* }
|
|
272
182
|
*
|
|
273
183
|
* function draw() {
|
|
274
|
-
* background(
|
|
184
|
+
* background(220);
|
|
185
|
+
* strokeWeight(2);
|
|
186
|
+
* translate(width / 2, height / 2);
|
|
275
187
|
*
|
|
276
|
-
*
|
|
277
|
-
* noFill();
|
|
278
|
-
* stroke(0);
|
|
279
|
-
* strokeWeight(1);
|
|
188
|
+
* time = dTime * frameCount;
|
|
280
189
|
*
|
|
281
|
-
* // Start drawing the shape.
|
|
282
190
|
* beginShape();
|
|
283
|
-
*
|
|
284
|
-
*
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
* // Add the anchor points.
|
|
289
|
-
* splineVertex(21, 17);
|
|
290
|
-
* splineVertex(68, 19);
|
|
291
|
-
*
|
|
292
|
-
* // Add the second control point and draw a segment to it.
|
|
293
|
-
* splineVertex(84, 91);
|
|
294
|
-
* splineVertex(84, 91);
|
|
295
|
-
*
|
|
296
|
-
* // Stop drawing the shape.
|
|
297
|
-
* endShape();
|
|
298
|
-
*
|
|
299
|
-
* // Style the anchor and control points.
|
|
300
|
-
* strokeWeight(5);
|
|
301
|
-
*
|
|
302
|
-
* // Draw the anchor points in black.
|
|
303
|
-
* stroke(0);
|
|
304
|
-
* point(21, 17);
|
|
305
|
-
* point(68, 19);
|
|
306
|
-
*
|
|
307
|
-
* // Draw the control points in red.
|
|
308
|
-
* stroke(255, 0, 0);
|
|
309
|
-
* point(x1, y1);
|
|
310
|
-
* point(84, 91);
|
|
191
|
+
* for (let i = 0; i < vertexCount; i++) {
|
|
192
|
+
* unit.rotate(dTheta);
|
|
193
|
+
* dRadius = noise(offset + unit.x, offset + unit.y, time) * ringWidth;
|
|
194
|
+
* radius = ringInnerRadius + dRadius;
|
|
195
|
+
* splineVertex(radius * unit.x, radius * unit.y);
|
|
311
196
|
* }
|
|
312
|
-
*
|
|
313
|
-
* // Start changing the first control point if the user clicks near it.
|
|
314
|
-
* function mousePressed() {
|
|
315
|
-
* if (dist(mouseX, mouseY, x1, y1) < 20) {
|
|
316
|
-
* isChanging = true;
|
|
317
|
-
* }
|
|
318
|
-
* }
|
|
319
|
-
*
|
|
320
|
-
* // Stop changing the first control point when the user releases the mouse.
|
|
321
|
-
* function mouseReleased() {
|
|
322
|
-
* isChanging = false;
|
|
323
|
-
* }
|
|
324
|
-
*
|
|
325
|
-
* // Update the first control point while the user drags the mouse.
|
|
326
|
-
* function mouseDragged() {
|
|
327
|
-
* if (isChanging === true) {
|
|
328
|
-
* x1 = mouseX;
|
|
329
|
-
* y1 = mouseY;
|
|
330
|
-
* }
|
|
331
|
-
* }
|
|
332
|
-
* </code>
|
|
333
|
-
* </div>
|
|
334
|
-
*
|
|
335
|
-
* <div>
|
|
336
|
-
* <code>
|
|
337
|
-
* function setup() {
|
|
338
|
-
* createCanvas(100, 100);
|
|
339
|
-
*
|
|
340
|
-
* background(200);
|
|
341
|
-
*
|
|
342
|
-
* // Start drawing the shape.
|
|
343
|
-
* beginShape();
|
|
344
|
-
*
|
|
345
|
-
* // Add the first control point and draw a segment to it.
|
|
346
|
-
* splineVertex(32, 91);
|
|
347
|
-
* splineVertex(32, 91);
|
|
348
|
-
*
|
|
349
|
-
* // Add the anchor points.
|
|
350
|
-
* splineVertex(21, 17);
|
|
351
|
-
* splineVertex(68, 19);
|
|
352
|
-
*
|
|
353
|
-
* // Add the second control point.
|
|
354
|
-
* splineVertex(84, 91);
|
|
355
|
-
* splineVertex(84, 91);
|
|
356
|
-
*
|
|
357
|
-
* // Stop drawing the shape.
|
|
358
|
-
* endShape();
|
|
359
|
-
*
|
|
360
|
-
* describe('A ghost shape drawn in white on a gray background.');
|
|
197
|
+
* endShape(CLOSE);
|
|
361
198
|
* }
|
|
362
199
|
* </code>
|
|
363
200
|
* </div>
|
|
@@ -422,47 +259,146 @@ function splineVertex(x: number, y: number, u: number, v: number): void;
|
|
|
422
259
|
function splineVertex(x: number, y: number, z: number, u: number, v: number): void;
|
|
423
260
|
|
|
424
261
|
/**
|
|
425
|
-
*
|
|
426
|
-
*
|
|
427
|
-
*
|
|
428
|
-
*
|
|
429
|
-
*
|
|
430
|
-
*
|
|
431
|
-
*
|
|
432
|
-
*
|
|
433
|
-
*
|
|
434
|
-
*
|
|
435
|
-
* (
|
|
436
|
-
*
|
|
437
|
-
*
|
|
262
|
+
* Gets or sets a given spline property.Use `splineProperty()` to adjust the behavior of splines
|
|
263
|
+
* created with `splineVertex()` or `spline()`. You can control
|
|
264
|
+
* two key aspects of a spline: its end behavior (`ends`) and
|
|
265
|
+
* its curvature (`tightness`).By default, the ends property is set to `INCLUDE`, which means
|
|
266
|
+
* the spline passes through every point, including the endpoints.
|
|
267
|
+
* You can also set it to `EXCLUDE` i.e. `splineProperty('ends', EXCLUDE)`,
|
|
268
|
+
* which makes the spline pass through all points except the endpoints.`INCLUDE` case will have the spline passing through
|
|
269
|
+
* all points, like this:`splineProperty('ends', INCLUDE); // no need to set this, as it is the default
|
|
270
|
+
* spline(25, 46, 93, 44, 93, 81, 35, 85);
|
|
271
|
+
*
|
|
272
|
+
* point(25, 46);
|
|
273
|
+
* point(93, 44);
|
|
274
|
+
* point(93, 81);
|
|
275
|
+
* point(35, 85);`EXCLUDE case will have the spline passing through
|
|
276
|
+
* the middle points, like this:`splineProperty('ends', INCLUDE);
|
|
277
|
+
* spline(25, 46, 93, 44, 93, 81, 35, 85);
|
|
278
|
+
*
|
|
279
|
+
* point(25, 46);
|
|
280
|
+
* point(93, 44);
|
|
281
|
+
* point(93, 81);
|
|
282
|
+
* point(35, 85);`By default, the tightness property is set to `0`,
|
|
283
|
+
* producing a smooth curve that passes evenly through
|
|
284
|
+
* the vertices. Negative values make the curve looser,
|
|
285
|
+
* while positive values make it tighter. Common values
|
|
286
|
+
* range between -1 and 1, though values outside this
|
|
287
|
+
* range can also be used for different effects.For example, To set tightness, use `splineProperty('tightness', t)`,
|
|
288
|
+
* (default: t = 0).Here's the example showing negetive value of tightness,
|
|
289
|
+
* which creates a rounder bulge:`splineProperty('tightness', -5)
|
|
290
|
+
* stroke(0);
|
|
291
|
+
* strokeWeight(2);
|
|
292
|
+
* spline(25, 46, 93, 44, 93, 81, 35, 85);`Here's the example showing positive value of tightness,
|
|
293
|
+
* which makes the curve tighter and more angular:`splineProperty('tightness', 5)
|
|
294
|
+
* stroke(0);
|
|
295
|
+
* strokeWeight(2);
|
|
296
|
+
* spline(25, 46, 93, 44, 93, 81, 35, 85);`In all cases, the splines in p5.js are cardinal splines.
|
|
297
|
+
* When tightness is 0, these splines are often known as
|
|
298
|
+
* Catmull-Rom splines
|
|
438
299
|
*
|
|
439
300
|
* @param Value to set the given property to.
|
|
440
301
|
* @example <div>
|
|
441
302
|
* <code>
|
|
442
303
|
* // Move the mouse left and right to see the curve change.
|
|
443
304
|
*
|
|
305
|
+
* let t;
|
|
306
|
+
*
|
|
444
307
|
* function setup() {
|
|
445
308
|
* createCanvas(100, 100);
|
|
446
|
-
*
|
|
309
|
+
*
|
|
447
310
|
* }
|
|
448
311
|
*
|
|
449
312
|
* function draw() {
|
|
450
|
-
* background(
|
|
313
|
+
* background(240);
|
|
451
314
|
*
|
|
452
|
-
*
|
|
453
|
-
* let t = map(mouseX, 0, 100, -5, 5, true);
|
|
315
|
+
* t = map(mouseX, 0, width, -5, 5, true);
|
|
454
316
|
* splineProperty('tightness', t);
|
|
455
317
|
*
|
|
456
|
-
* // Draw the curve.
|
|
457
318
|
* noFill();
|
|
319
|
+
* stroke(0);
|
|
320
|
+
* strokeWeight(2);
|
|
321
|
+
*
|
|
458
322
|
* beginShape();
|
|
459
323
|
* splineVertex(10, 26);
|
|
460
|
-
* splineVertex(10, 26);
|
|
461
324
|
* splineVertex(83, 24);
|
|
325
|
+
*
|
|
462
326
|
* splineVertex(83, 61);
|
|
463
327
|
* splineVertex(25, 65);
|
|
464
|
-
* splineVertex(25, 65);
|
|
465
328
|
* endShape();
|
|
329
|
+
*
|
|
330
|
+
* push();
|
|
331
|
+
* strokeWeight(5);
|
|
332
|
+
* point(10, 26);
|
|
333
|
+
* point(83, 24);
|
|
334
|
+
* point(83, 61);
|
|
335
|
+
* point(25, 65);
|
|
336
|
+
* pop();
|
|
337
|
+
*
|
|
338
|
+
* fill(0);
|
|
339
|
+
* noStroke();
|
|
340
|
+
* textSize(10);
|
|
341
|
+
* text(`tightness: ${round(t, 1)}`, 15, 90);
|
|
342
|
+
* 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.');
|
|
343
|
+
* }
|
|
344
|
+
* </code>
|
|
345
|
+
* </div>
|
|
346
|
+
* @example <div>
|
|
347
|
+
* <code>
|
|
348
|
+
* function setup() {
|
|
349
|
+
* createCanvas(360, 140);
|
|
350
|
+
* background(240);
|
|
351
|
+
* noFill();
|
|
352
|
+
*
|
|
353
|
+
* // Right panel: ends = INCLUDE (all spans).
|
|
354
|
+
* push();
|
|
355
|
+
* translate(10, 10);
|
|
356
|
+
* stroke(220);
|
|
357
|
+
* rect(0, 0, 160, 120);
|
|
358
|
+
* fill(30);
|
|
359
|
+
* textSize(11);
|
|
360
|
+
* text('ends: INCLUDE (all spans)', 8, 16);
|
|
361
|
+
* noFill();
|
|
362
|
+
*
|
|
363
|
+
* splineProperty('ends', INCLUDE);
|
|
364
|
+
* stroke(0);
|
|
365
|
+
* strokeWeight(2);
|
|
366
|
+
* spline(25, 46, 93, 44, 93, 81, 35, 85);
|
|
367
|
+
*
|
|
368
|
+
* // vertices
|
|
369
|
+
* strokeWeight(5);
|
|
370
|
+
* stroke(0);
|
|
371
|
+
* point(25, 46);
|
|
372
|
+
* point(93, 44);
|
|
373
|
+
* point(93, 81);
|
|
374
|
+
* point(35, 85);
|
|
375
|
+
* pop();
|
|
376
|
+
*
|
|
377
|
+
* // Right panel: ends = EXCLUDE (middle only).
|
|
378
|
+
* push();
|
|
379
|
+
* translate(190, 10);
|
|
380
|
+
* stroke(220);
|
|
381
|
+
* rect(0, 0, 160, 120);
|
|
382
|
+
* noStroke();
|
|
383
|
+
* fill(30);
|
|
384
|
+
* text('ends: EXCLUDE ', 18, 16);
|
|
385
|
+
* noFill();
|
|
386
|
+
*
|
|
387
|
+
* splineProperty('ends', EXCLUDE);
|
|
388
|
+
* stroke(0);
|
|
389
|
+
* strokeWeight(2);
|
|
390
|
+
* spline(25, 46, 93, 44, 93, 81, 35, 85);
|
|
391
|
+
*
|
|
392
|
+
* // vertices
|
|
393
|
+
* strokeWeight(5);
|
|
394
|
+
* stroke(0);
|
|
395
|
+
* point(25, 46);
|
|
396
|
+
* point(93, 44);
|
|
397
|
+
* point(93, 81);
|
|
398
|
+
* point(35, 85);
|
|
399
|
+
* pop();
|
|
400
|
+
*
|
|
401
|
+
* describe('Left panel shows spline with ends INCLUDE (three spans). Right panel shows EXCLUDE (only the middle span). Four black points mark the vertices.');
|
|
466
402
|
* }
|
|
467
403
|
* </code>
|
|
468
404
|
* </div>
|