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/types/p5.d.ts
CHANGED
|
@@ -3456,7 +3456,7 @@ declare class p5 {
|
|
|
3456
3456
|
* Draws a Bézier curve.Bézier curves can form shapes and curves that slope gently. They're defined
|
|
3457
3457
|
* by two anchor points and two control points. Bézier curves provide more
|
|
3458
3458
|
* control than the spline curves created with the
|
|
3459
|
-
*
|
|
3459
|
+
* spline() function.The first two parameters, `x1` and `y1`, set the first anchor point. The
|
|
3460
3460
|
* first anchor point is where the curve starts.The next four parameters, `x2`, `y2`, `x3`, and `y3`, set the two control
|
|
3461
3461
|
* points. The control points "pull" the curve towards them.The seventh and eighth parameters, `x4` and `y4`, set the last anchor
|
|
3462
3462
|
* point. The last anchor point is where the curve ends.Bézier curves can also be drawn in 3D using WebGL mode. The 3D version of
|
|
@@ -3519,13 +3519,11 @@ declare class p5 {
|
|
|
3519
3519
|
|
|
3520
3520
|
/**
|
|
3521
3521
|
* Draws a curve using a Catmull-Rom spline.Spline curves can form shapes and curves that slope gently. They’re like
|
|
3522
|
-
* cables that are attached to a set of points.
|
|
3523
|
-
*
|
|
3524
|
-
*
|
|
3525
|
-
* points
|
|
3526
|
-
*
|
|
3527
|
-
* point. This point isn’t drawn and can be thought of as the curve’s ending
|
|
3528
|
-
* point.Spline curves can also be drawn in 3D using WebGL mode. The 3D version of
|
|
3522
|
+
* cables that are attached to a set of points. By default (`ends: INCLUDE`),
|
|
3523
|
+
* the curve passes through all four points you provide, in order
|
|
3524
|
+
* `p0(x1,y1)` -> `p1(x2,y2)` -> `p2(x3,y3)` -> `p3(x4,y4)`. Think of them as
|
|
3525
|
+
* points on a curve. If you switch to `ends: EXCLUDE`, p0 and p3 act
|
|
3526
|
+
* like control points and only the middle span `p1->p2` is drawn.Spline curves can also be drawn in 3D using WebGL mode. The 3D version of
|
|
3529
3527
|
* `spline()` has twelve arguments because each point has x-, y-, and
|
|
3530
3528
|
* z-coordinates.
|
|
3531
3529
|
*
|
|
@@ -3543,15 +3541,15 @@ declare class p5 {
|
|
|
3543
3541
|
spline(x1: number, y1: number, z1: number, x2: number, y2: number, z2: number, x3: number, y3: number, z3: number, x4: number, y4: number, z4: number): void;
|
|
3544
3542
|
|
|
3545
3543
|
/**
|
|
3546
|
-
* Calculates coordinates along a spline curve using interpolation.`splinePoint()` calculates coordinates along a spline curve using
|
|
3547
|
-
*
|
|
3544
|
+
* Calculates coordinates along a spline curve using interpolation.`splinePoint()` calculates coordinates along a spline curve using four
|
|
3545
|
+
* points p0, p1, p2, p3. It expects points in the same order as the
|
|
3548
3546
|
* spline() function. `splinePoint()` works one axis
|
|
3549
|
-
* at a time. Passing the
|
|
3550
|
-
* calculate the x-coordinate of a point on the curve. Passing the
|
|
3551
|
-
*
|
|
3552
|
-
* the curve.The first parameter, `a`, is the coordinate of
|
|
3553
|
-
*
|
|
3554
|
-
*
|
|
3547
|
+
* at a time. Passing the points' x-coordinates will
|
|
3548
|
+
* calculate the x-coordinate of a point on the curve. Passing the
|
|
3549
|
+
* points' y-coordinates will calculate the y-coordinate of a point on
|
|
3550
|
+
* the curve.The first parameter, `a`, is the coordinate of point p0.The second and third parameters, `b` and `c`, are the coordinates of
|
|
3551
|
+
* points p1 and p2.The fourth parameter, `d`, is the coordinate of point p3.The fifth parameter, `t`, is the amount to interpolate along the span
|
|
3552
|
+
* from p1 to p2. `t = 0` is p1, `t = 1` is p2, and `t = 0.5` is halfway
|
|
3555
3553
|
* between them.
|
|
3556
3554
|
*
|
|
3557
3555
|
* @param
|
|
@@ -3564,15 +3562,14 @@ declare class p5 {
|
|
|
3564
3562
|
|
|
3565
3563
|
/**
|
|
3566
3564
|
* Calculates coordinates along a line that's tangent to a spline curve.Tangent lines skim the surface of a curve. A tangent line's slope equals
|
|
3567
|
-
* the curve's slope at the point where it intersects.`splineTangent()` calculates coordinates along a tangent line using
|
|
3568
|
-
*
|
|
3569
|
-
*
|
|
3570
|
-
*
|
|
3571
|
-
*
|
|
3572
|
-
*
|
|
3573
|
-
*
|
|
3574
|
-
*
|
|
3575
|
-
* is the first anchor point, 1 is the second anchor point, and 0.5 is halfway
|
|
3565
|
+
* the curve's slope at the point where it intersects.`splineTangent()` calculates coordinates along a tangent line using four
|
|
3566
|
+
* points p0, p1, p2, p3. It expects points in the same order as the
|
|
3567
|
+
* spline() function. `splineTangent()` works one
|
|
3568
|
+
* axis at a time. Passing the points' x-coordinates returns the x-component of
|
|
3569
|
+
* the tangent vector; passing the points' y-coordinates returns the y-component.
|
|
3570
|
+
* The first parameter, `a`, is the coordinate of point p0.The second and third parameters, `b` and `c`, are the coordinates of
|
|
3571
|
+
* points p1 and p2.The fourth parameter, `d`, is the coordinate of point p3.The fifth parameter, `t`, is the amount to interpolate along the span
|
|
3572
|
+
* from p1 to p2. `t = 0` is p1, `t = 1` is p2, and `t = 0.5` is halfway
|
|
3576
3573
|
* between them.
|
|
3577
3574
|
*
|
|
3578
3575
|
* @param
|
|
@@ -3607,49 +3604,44 @@ declare class p5 {
|
|
|
3607
3604
|
bezierOrder(): number;
|
|
3608
3605
|
|
|
3609
3606
|
/**
|
|
3610
|
-
*
|
|
3611
|
-
* it creates
|
|
3612
|
-
*
|
|
3613
|
-
* between the
|
|
3607
|
+
* Connects points with a smooth curve (a spline).`splineVertex()` adds a curved segment to custom shapes.
|
|
3608
|
+
* The curve it creates follows the same rules as the ones
|
|
3609
|
+
* made with the spline() function.
|
|
3610
|
+
* `splineVertex()` must be called between the
|
|
3611
|
+
* beginShape() and
|
|
3614
3612
|
* endShape() functions.Spline curves can form shapes and curves that slope gently. They’re like
|
|
3615
|
-
* cables that are attached to a set of points.
|
|
3616
|
-
*
|
|
3617
|
-
* least four times between
|
|
3613
|
+
* cables that are attached to a set of points. `splineVertex()` draws a smooth
|
|
3614
|
+
* curve through the points you give it.
|
|
3618
3615
|
* beginShape() and
|
|
3619
|
-
* endShape() in order to draw a curve
|
|
3616
|
+
* endShape() in order to draw a curve:If you provide three points, the spline will pass through them.
|
|
3617
|
+
* It works the same way with any number of points.`beginShape();
|
|
3620
3618
|
*
|
|
3621
|
-
* // Add the first
|
|
3622
|
-
* splineVertex(
|
|
3619
|
+
* // Add the first point.
|
|
3620
|
+
* splineVertex(25, 80);
|
|
3623
3621
|
*
|
|
3624
|
-
* // Add the
|
|
3625
|
-
* splineVertex(
|
|
3626
|
-
* splineVertex(21, 17);
|
|
3622
|
+
* // Add the second point.
|
|
3623
|
+
* splineVertex(20, 30);
|
|
3627
3624
|
*
|
|
3628
|
-
* // Add the
|
|
3629
|
-
* splineVertex(
|
|
3625
|
+
* // Add the last point.
|
|
3626
|
+
* splineVertex(85, 60);
|
|
3630
3627
|
*
|
|
3631
|
-
* endShape();`
|
|
3632
|
-
* similar to the curve() function. The segments
|
|
3633
|
-
* between the control and anchor points can be drawn by calling
|
|
3634
|
-
* `splineVertex()` with the coordinates of the control points:`beginShape();
|
|
3628
|
+
* endShape();`Passing in `CLOSE` to `endShape()` closes the spline smoothly.`beginShape();
|
|
3635
3629
|
*
|
|
3636
|
-
* // Add the first
|
|
3637
|
-
* splineVertex(
|
|
3638
|
-
* splineVertex(84, 91);
|
|
3630
|
+
* // Add the first point.
|
|
3631
|
+
* splineVertex(25, 80);
|
|
3639
3632
|
*
|
|
3640
|
-
* // Add the
|
|
3641
|
-
* splineVertex(
|
|
3642
|
-
* splineVertex(21, 17);
|
|
3633
|
+
* // Add the second point.
|
|
3634
|
+
* splineVertex(20, 30);
|
|
3643
3635
|
*
|
|
3644
|
-
* // Add the second
|
|
3645
|
-
* splineVertex(
|
|
3636
|
+
* // Add the second point.
|
|
3637
|
+
* splineVertex(85, 60);
|
|
3646
3638
|
*
|
|
3647
|
-
*
|
|
3648
|
-
*
|
|
3649
|
-
*
|
|
3650
|
-
*
|
|
3651
|
-
*
|
|
3652
|
-
*
|
|
3639
|
+
* endShape(CLOSE);`By default (`ends: INCLUDE`), the curve passes through
|
|
3640
|
+
* all the points you add with `splineVertex()`, similar to
|
|
3641
|
+
* the spline() function. To draw only
|
|
3642
|
+
* the middle span p1->p2 (skipping p0->p1 and p2->p3), set
|
|
3643
|
+
* `splineProperty('ends', EXCLUDE)`. You don’t need to duplicate
|
|
3644
|
+
* vertices to draw those spans.Spline curves can also be drawn in 3D using WebGL mode. The 3D version of
|
|
3653
3645
|
* `splineVertex()` has three arguments because each point has x-, y-, and
|
|
3654
3646
|
* z-coordinates. By default, the vertex’s z-coordinate is set to 0.Note: `splineVertex()` won’t work when an argument is passed to
|
|
3655
3647
|
* beginShape().
|
|
@@ -3666,19 +3658,43 @@ declare class p5 {
|
|
|
3666
3658
|
splineVertex(x: number, y: number, z: number, u: number, v: number): void;
|
|
3667
3659
|
|
|
3668
3660
|
/**
|
|
3669
|
-
*
|
|
3670
|
-
*
|
|
3671
|
-
*
|
|
3672
|
-
*
|
|
3673
|
-
*
|
|
3674
|
-
*
|
|
3675
|
-
*
|
|
3676
|
-
*
|
|
3677
|
-
*
|
|
3678
|
-
*
|
|
3679
|
-
* (
|
|
3680
|
-
*
|
|
3681
|
-
*
|
|
3661
|
+
* Gets or sets a given spline property.Use `splineProperty()` to adjust the behavior of splines
|
|
3662
|
+
* created with `splineVertex()` or `spline()`. You can control
|
|
3663
|
+
* two key aspects of a spline: its end behavior (`ends`) and
|
|
3664
|
+
* its curvature (`tightness`).By default, the ends property is set to `INCLUDE`, which means
|
|
3665
|
+
* the spline passes through every point, including the endpoints.
|
|
3666
|
+
* You can also set it to `EXCLUDE` i.e. `splineProperty('ends', EXCLUDE)`,
|
|
3667
|
+
* which makes the spline pass through all points except the endpoints.`INCLUDE` case will have the spline passing through
|
|
3668
|
+
* all points, like this:`splineProperty('ends', INCLUDE); // no need to set this, as it is the default
|
|
3669
|
+
* spline(25, 46, 93, 44, 93, 81, 35, 85);
|
|
3670
|
+
*
|
|
3671
|
+
* point(25, 46);
|
|
3672
|
+
* point(93, 44);
|
|
3673
|
+
* point(93, 81);
|
|
3674
|
+
* point(35, 85);`EXCLUDE case will have the spline passing through
|
|
3675
|
+
* the middle points, like this:`splineProperty('ends', INCLUDE);
|
|
3676
|
+
* spline(25, 46, 93, 44, 93, 81, 35, 85);
|
|
3677
|
+
*
|
|
3678
|
+
* point(25, 46);
|
|
3679
|
+
* point(93, 44);
|
|
3680
|
+
* point(93, 81);
|
|
3681
|
+
* point(35, 85);`By default, the tightness property is set to `0`,
|
|
3682
|
+
* producing a smooth curve that passes evenly through
|
|
3683
|
+
* the vertices. Negative values make the curve looser,
|
|
3684
|
+
* while positive values make it tighter. Common values
|
|
3685
|
+
* range between -1 and 1, though values outside this
|
|
3686
|
+
* range can also be used for different effects.For example, To set tightness, use `splineProperty('tightness', t)`,
|
|
3687
|
+
* (default: t = 0).Here's the example showing negetive value of tightness,
|
|
3688
|
+
* which creates a rounder bulge:`splineProperty('tightness', -5)
|
|
3689
|
+
* stroke(0);
|
|
3690
|
+
* strokeWeight(2);
|
|
3691
|
+
* spline(25, 46, 93, 44, 93, 81, 35, 85);`Here's the example showing positive value of tightness,
|
|
3692
|
+
* which makes the curve tighter and more angular:`splineProperty('tightness', 5)
|
|
3693
|
+
* stroke(0);
|
|
3694
|
+
* strokeWeight(2);
|
|
3695
|
+
* spline(25, 46, 93, 44, 93, 81, 35, 85);`In all cases, the splines in p5.js are cardinal splines.
|
|
3696
|
+
* When tightness is 0, these splines are often known as
|
|
3697
|
+
* Catmull-Rom splines
|
|
3682
3698
|
*
|
|
3683
3699
|
* @param
|
|
3684
3700
|
* @param
|
package/types/shape/curves.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ declare module 'p5' {
|
|
|
7
7
|
* Draws a Bézier curve.Bézier curves can form shapes and curves that slope gently. They're defined
|
|
8
8
|
* by two anchor points and two control points. Bézier curves provide more
|
|
9
9
|
* control than the spline curves created with the
|
|
10
|
-
*
|
|
10
|
+
* spline() function.The first two parameters, `x1` and `y1`, set the first anchor point. The
|
|
11
11
|
* first anchor point is where the curve starts.The next four parameters, `x2`, `y2`, `x3`, and `y3`, set the two control
|
|
12
12
|
* points. The control points "pull" the curve towards them.The seventh and eighth parameters, `x4` and `y4`, set the last anchor
|
|
13
13
|
* point. The last anchor point is where the curve ends.Bézier curves can also be drawn in 3D using WebGL mode. The 3D version of
|
|
@@ -374,49 +374,72 @@ function bezierTangent(a: number, b: number, c: number, d: number, t: number): n
|
|
|
374
374
|
|
|
375
375
|
/**
|
|
376
376
|
* Draws a curve using a Catmull-Rom spline.Spline curves can form shapes and curves that slope gently. They’re like
|
|
377
|
-
* cables that are attached to a set of points.
|
|
378
|
-
*
|
|
379
|
-
*
|
|
380
|
-
* points
|
|
381
|
-
*
|
|
382
|
-
* point. This point isn’t drawn and can be thought of as the curve’s ending
|
|
383
|
-
* point.Spline curves can also be drawn in 3D using WebGL mode. The 3D version of
|
|
377
|
+
* cables that are attached to a set of points. By default (`ends: INCLUDE`),
|
|
378
|
+
* the curve passes through all four points you provide, in order
|
|
379
|
+
* `p0(x1,y1)` -> `p1(x2,y2)` -> `p2(x3,y3)` -> `p3(x4,y4)`. Think of them as
|
|
380
|
+
* points on a curve. If you switch to `ends: EXCLUDE`, p0 and p3 act
|
|
381
|
+
* like control points and only the middle span `p1->p2` is drawn.Spline curves can also be drawn in 3D using WebGL mode. The 3D version of
|
|
384
382
|
* `spline()` has twelve arguments because each point has x-, y-, and
|
|
385
383
|
* z-coordinates.
|
|
386
384
|
*
|
|
387
|
-
* @param x-coordinate of
|
|
388
|
-
* @param y-coordinate of
|
|
389
|
-
* @param x-coordinate of
|
|
390
|
-
* @param y-coordinate of
|
|
391
|
-
* @param x-coordinate of
|
|
392
|
-
* @param y-coordinate of
|
|
393
|
-
* @param x-coordinate of
|
|
394
|
-
* @param y-coordinate of
|
|
385
|
+
* @param x-coordinate of point p0.
|
|
386
|
+
* @param y-coordinate of point p0.
|
|
387
|
+
* @param x-coordinate of point p1.
|
|
388
|
+
* @param y-coordinate of point p1.
|
|
389
|
+
* @param x-coordinate of point p2.
|
|
390
|
+
* @param y-coordinate of point p2.
|
|
391
|
+
* @param x-coordinate of point p3.
|
|
392
|
+
* @param y-coordinate of point p3.
|
|
395
393
|
* @example <div>
|
|
396
394
|
* <code>
|
|
397
395
|
* function setup() {
|
|
396
|
+
* createCanvas(200, 200);
|
|
397
|
+
* background(240);
|
|
398
|
+
* noFill();
|
|
399
|
+
*
|
|
400
|
+
* stroke(0);
|
|
401
|
+
* strokeWeight(2);
|
|
402
|
+
* spline(40, 60, 100, 40, 120, 120, 60, 140);
|
|
403
|
+
*
|
|
404
|
+
* strokeWeight(5);
|
|
405
|
+
* point(40, 60);
|
|
406
|
+
* point(100, 40);
|
|
407
|
+
* point(120, 120);
|
|
408
|
+
* point(60, 140);
|
|
409
|
+
*
|
|
410
|
+
* describe('A black spline passes smoothly through four points');
|
|
411
|
+
* }
|
|
412
|
+
* </code>
|
|
413
|
+
* </div>
|
|
414
|
+
*
|
|
415
|
+
* <div>
|
|
416
|
+
* <code>
|
|
417
|
+
* function setup() {
|
|
398
418
|
* createCanvas(100, 100);
|
|
399
419
|
*
|
|
400
420
|
* background(200);
|
|
401
421
|
*
|
|
422
|
+
* // Exclude the ends—skip the outer spans (p0→p1 and p2→p3) so only the middle span (p1→p2) is drawn.
|
|
423
|
+
* splineProperty('ends', EXCLUDE);
|
|
424
|
+
*
|
|
402
425
|
* // Draw a black spline curve.
|
|
403
426
|
* noFill();
|
|
404
427
|
* strokeWeight(1);
|
|
405
428
|
* stroke(0);
|
|
406
429
|
* spline(5, 26, 73, 24, 73, 61, 15, 65);
|
|
407
430
|
*
|
|
408
|
-
* // Draw red spline curves from the
|
|
431
|
+
* // Draw red spline curves from the points.
|
|
409
432
|
* stroke(255, 0, 0);
|
|
410
433
|
* spline(5, 26, 5, 26, 73, 24, 73, 61);
|
|
411
434
|
* spline(73, 24, 73, 61, 15, 65, 15, 65);
|
|
412
435
|
*
|
|
413
|
-
* // Draw the
|
|
436
|
+
* // Draw the points in black.
|
|
414
437
|
* strokeWeight(5);
|
|
415
438
|
* stroke(0);
|
|
416
439
|
* point(73, 24);
|
|
417
440
|
* point(73, 61);
|
|
418
441
|
*
|
|
419
|
-
* // Draw the
|
|
442
|
+
* // Draw the points in red.
|
|
420
443
|
* stroke(255, 0, 0);
|
|
421
444
|
* point(5, 26);
|
|
422
445
|
* point(15, 65);
|
|
@@ -445,13 +468,16 @@ function bezierTangent(a: number, b: number, c: number, d: number, t: number): n
|
|
|
445
468
|
* function draw() {
|
|
446
469
|
* background(200);
|
|
447
470
|
*
|
|
471
|
+
* // Exclude the ends—skip the outer spans (p0→p1 and p2→p3) so only the middle span (p1→p2) is drawn.
|
|
472
|
+
* splineProperty('ends', EXCLUDE);
|
|
473
|
+
*
|
|
448
474
|
* // Draw a black spline curve.
|
|
449
475
|
* noFill();
|
|
450
476
|
* strokeWeight(1);
|
|
451
477
|
* stroke(0);
|
|
452
478
|
* spline(x1, y1, 73, 24, 73, 61, 15, 65);
|
|
453
479
|
*
|
|
454
|
-
* // Draw red spline curves from the
|
|
480
|
+
* // Draw red spline curves from the points.
|
|
455
481
|
* stroke(255, 0, 0);
|
|
456
482
|
* spline(x1, y1, x1, y1, 73, 24, 73, 61);
|
|
457
483
|
* spline(73, 24, 73, 61, 15, 65, 15, 65);
|
|
@@ -462,25 +488,25 @@ function bezierTangent(a: number, b: number, c: number, d: number, t: number): n
|
|
|
462
488
|
* point(73, 24);
|
|
463
489
|
* point(73, 61);
|
|
464
490
|
*
|
|
465
|
-
* // Draw the
|
|
491
|
+
* // Draw the points in red.
|
|
466
492
|
* stroke(255, 0, 0);
|
|
467
493
|
* point(x1, y1);
|
|
468
494
|
* point(15, 65);
|
|
469
495
|
* }
|
|
470
496
|
*
|
|
471
|
-
* // Start changing the first
|
|
497
|
+
* // Start changing the first point if the user clicks near it.
|
|
472
498
|
* function mousePressed() {
|
|
473
499
|
* if (dist(mouseX, mouseY, x1, y1) < 20) {
|
|
474
500
|
* isChanging = true;
|
|
475
501
|
* }
|
|
476
502
|
* }
|
|
477
503
|
*
|
|
478
|
-
* // Stop changing the first
|
|
504
|
+
* // Stop changing the first point when the user releases the mouse.
|
|
479
505
|
* function mouseReleased() {
|
|
480
506
|
* isChanging = false;
|
|
481
507
|
* }
|
|
482
508
|
*
|
|
483
|
-
* // Update the first
|
|
509
|
+
* // Update the first point while the user drags the mouse.
|
|
484
510
|
* function mouseDragged() {
|
|
485
511
|
* if (isChanging === true) {
|
|
486
512
|
* x1 = mouseX;
|
|
@@ -497,6 +523,9 @@ function bezierTangent(a: number, b: number, c: number, d: number, t: number): n
|
|
|
497
523
|
*
|
|
498
524
|
* background('skyblue');
|
|
499
525
|
*
|
|
526
|
+
* // Exclude the ends—skip the outer spans (p0→p1 and p2→p3) so only the middle span (p1→p2) is drawn.
|
|
527
|
+
* splineProperty('ends', EXCLUDE);
|
|
528
|
+
*
|
|
500
529
|
* // Draw the red balloon.
|
|
501
530
|
* fill('red');
|
|
502
531
|
* spline(-150, 275, 50, 60, 50, 60, 250, 275);
|
|
@@ -520,6 +549,9 @@ function bezierTangent(a: number, b: number, c: number, d: number, t: number): n
|
|
|
520
549
|
* function draw() {
|
|
521
550
|
* background('skyblue');
|
|
522
551
|
*
|
|
552
|
+
* // Exclude the ends—skip the outer spans (p0→p1 and p2→p3) so only the middle span (p1→p2) is drawn.
|
|
553
|
+
* splineProperty('ends', EXCLUDE);
|
|
554
|
+
*
|
|
523
555
|
* // Rotate around the y-axis.
|
|
524
556
|
* rotateY(frameCount * 0.01);
|
|
525
557
|
*
|
|
@@ -536,29 +568,29 @@ function bezierTangent(a: number, b: number, c: number, d: number, t: number): n
|
|
|
536
568
|
function spline(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, x4: number, y4: number): void;
|
|
537
569
|
|
|
538
570
|
/**
|
|
539
|
-
* @param z-coordinate of
|
|
540
|
-
* @param z-coordinate of
|
|
541
|
-
* @param z-coordinate of
|
|
542
|
-
* @param z-coordinate of
|
|
571
|
+
* @param z-coordinate of point p0.
|
|
572
|
+
* @param z-coordinate of point p1.
|
|
573
|
+
* @param z-coordinate of point p2.
|
|
574
|
+
* @param z-coordinate of point p3.
|
|
543
575
|
*/
|
|
544
576
|
function spline(x1: number, y1: number, z1: number, x2: number, y2: number, z2: number, x3: number, y3: number, z3: number, x4: number, y4: number, z4: number): void;
|
|
545
577
|
|
|
546
578
|
/**
|
|
547
|
-
* Calculates coordinates along a spline curve using interpolation.`splinePoint()` calculates coordinates along a spline curve using
|
|
548
|
-
*
|
|
579
|
+
* Calculates coordinates along a spline curve using interpolation.`splinePoint()` calculates coordinates along a spline curve using four
|
|
580
|
+
* points p0, p1, p2, p3. It expects points in the same order as the
|
|
549
581
|
* spline() function. `splinePoint()` works one axis
|
|
550
|
-
* at a time. Passing the
|
|
551
|
-
* calculate the x-coordinate of a point on the curve. Passing the
|
|
552
|
-
*
|
|
553
|
-
* the curve.The first parameter, `a`, is the coordinate of
|
|
554
|
-
*
|
|
555
|
-
*
|
|
582
|
+
* at a time. Passing the points' x-coordinates will
|
|
583
|
+
* calculate the x-coordinate of a point on the curve. Passing the
|
|
584
|
+
* points' y-coordinates will calculate the y-coordinate of a point on
|
|
585
|
+
* the curve.The first parameter, `a`, is the coordinate of point p0.The second and third parameters, `b` and `c`, are the coordinates of
|
|
586
|
+
* points p1 and p2.The fourth parameter, `d`, is the coordinate of point p3.The fifth parameter, `t`, is the amount to interpolate along the span
|
|
587
|
+
* from p1 to p2. `t = 0` is p1, `t = 1` is p2, and `t = 0.5` is halfway
|
|
556
588
|
* between them.
|
|
557
589
|
*
|
|
558
|
-
* @param coordinate of
|
|
559
|
-
* @param coordinate of
|
|
560
|
-
* @param coordinate of
|
|
561
|
-
* @param coordinate of
|
|
590
|
+
* @param coordinate of point p0.
|
|
591
|
+
* @param coordinate of point p1.
|
|
592
|
+
* @param coordinate of point p2.
|
|
593
|
+
* @param coordinate of point p3.
|
|
562
594
|
* @param amount to interpolate between 0 and 1.
|
|
563
595
|
* @return coordinate of a point on the curve.
|
|
564
596
|
* @example <div>
|
|
@@ -568,7 +600,7 @@ function spline(x1: number, y1: number, z1: number, x2: number, y2: number, z2:
|
|
|
568
600
|
*
|
|
569
601
|
* background(200);
|
|
570
602
|
*
|
|
571
|
-
* // Set the coordinates for the curve's
|
|
603
|
+
* // Set the coordinates for the curve's four points (p0, p1, p2, p3).
|
|
572
604
|
* let x1 = 5;
|
|
573
605
|
* let y1 = 26;
|
|
574
606
|
* let x2 = 73;
|
|
@@ -616,7 +648,7 @@ function spline(x1: number, y1: number, z1: number, x2: number, y2: number, z2:
|
|
|
616
648
|
* function draw() {
|
|
617
649
|
* background(200);
|
|
618
650
|
*
|
|
619
|
-
* // Set the coordinates for the curve's
|
|
651
|
+
* // Set the coordinates for the curve's four points (p0, p1, p2, p3).
|
|
620
652
|
* let x1 = 5;
|
|
621
653
|
* let y1 = 26;
|
|
622
654
|
* let x2 = 73;
|
|
@@ -646,31 +678,73 @@ function splinePoint(a: number, b: number, c: number, d: number, t: number): num
|
|
|
646
678
|
|
|
647
679
|
/**
|
|
648
680
|
* Calculates coordinates along a line that's tangent to a spline curve.Tangent lines skim the surface of a curve. A tangent line's slope equals
|
|
649
|
-
* the curve's slope at the point where it intersects.`splineTangent()` calculates coordinates along a tangent line using
|
|
650
|
-
*
|
|
651
|
-
*
|
|
652
|
-
*
|
|
653
|
-
*
|
|
654
|
-
*
|
|
655
|
-
*
|
|
656
|
-
*
|
|
657
|
-
* is the first anchor point, 1 is the second anchor point, and 0.5 is halfway
|
|
681
|
+
* the curve's slope at the point where it intersects.`splineTangent()` calculates coordinates along a tangent line using four
|
|
682
|
+
* points p0, p1, p2, p3. It expects points in the same order as the
|
|
683
|
+
* spline() function. `splineTangent()` works one
|
|
684
|
+
* axis at a time. Passing the points' x-coordinates returns the x-component of
|
|
685
|
+
* the tangent vector; passing the points' y-coordinates returns the y-component.
|
|
686
|
+
* The first parameter, `a`, is the coordinate of point p0.The second and third parameters, `b` and `c`, are the coordinates of
|
|
687
|
+
* points p1 and p2.The fourth parameter, `d`, is the coordinate of point p3.The fifth parameter, `t`, is the amount to interpolate along the span
|
|
688
|
+
* from p1 to p2. `t = 0` is p1, `t = 1` is p2, and `t = 0.5` is halfway
|
|
658
689
|
* between them.
|
|
659
690
|
*
|
|
660
|
-
* @param coordinate of
|
|
661
|
-
* @param coordinate of
|
|
662
|
-
* @param coordinate of
|
|
663
|
-
* @param coordinate of
|
|
691
|
+
* @param coordinate of point p0.
|
|
692
|
+
* @param coordinate of point p1.
|
|
693
|
+
* @param coordinate of point p2.
|
|
694
|
+
* @param coordinate of point p3.
|
|
664
695
|
* @param amount to interpolate between 0 and 1.
|
|
665
696
|
* @return coordinate of a point on the tangent line.
|
|
666
697
|
* @example <div>
|
|
667
698
|
* <code>
|
|
668
699
|
* function setup() {
|
|
700
|
+
* createCanvas(120, 120);
|
|
701
|
+
* 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.');
|
|
702
|
+
* }
|
|
703
|
+
*
|
|
704
|
+
* function draw() {
|
|
705
|
+
* background(240);
|
|
706
|
+
*
|
|
707
|
+
* const x1 = 15, y1 = 40;
|
|
708
|
+
* const x2 = 90, y2 = 25;
|
|
709
|
+
* const x3 = 95, y3 = 95;
|
|
710
|
+
* const x4 = 30, y4 = 110;
|
|
711
|
+
*
|
|
712
|
+
* noFill();
|
|
713
|
+
* stroke(0);
|
|
714
|
+
* strokeWeight(2);
|
|
715
|
+
* spline(x1, y1, x2, y2, x3, y3, x4, y4);
|
|
716
|
+
*
|
|
717
|
+
* const t = 0.5 + 0.5 * sin(frameCount * 0.03);
|
|
718
|
+
*
|
|
719
|
+
* const px = splinePoint(x1, x2, x3, x4, t);
|
|
720
|
+
* const py = splinePoint(y1, y2, y3, y4, t);
|
|
721
|
+
*
|
|
722
|
+
* let tx = splineTangent(x1, x2, x3, x4, t);
|
|
723
|
+
* let ty = splineTangent(y1, y2, y3, y4, t);
|
|
724
|
+
*
|
|
725
|
+
* const m = Math.hypot(tx, ty) || 1;
|
|
726
|
+
* tx = (tx / m) * 16;
|
|
727
|
+
* ty = (ty / m) * 16;
|
|
728
|
+
*
|
|
729
|
+
* stroke(0);
|
|
730
|
+
* strokeWeight(2);
|
|
731
|
+
* line(px, py, px + tx, py + ty);
|
|
732
|
+
*
|
|
733
|
+
* noStroke();
|
|
734
|
+
* fill('red');
|
|
735
|
+
* circle(px, py, 7);
|
|
736
|
+
* }
|
|
737
|
+
* </code>
|
|
738
|
+
* </div>
|
|
739
|
+
*
|
|
740
|
+
* <div>
|
|
741
|
+
* <code>
|
|
742
|
+
* function setup() {
|
|
669
743
|
* createCanvas(100, 100);
|
|
670
744
|
*
|
|
671
745
|
* background(200);
|
|
672
746
|
*
|
|
673
|
-
* // Set the coordinates for the curve's
|
|
747
|
+
* // Set the coordinates for the curve's four points (p0, p1, p2, p3).
|
|
674
748
|
* let x1 = 5;
|
|
675
749
|
* let y1 = 26;
|
|
676
750
|
* let x2 = 73;
|