Skip to content

Commit 177e9b5

Browse files
authored
updating anchor/control points wordings in curve.js
1 parent 7da91e3 commit 177e9b5

1 file changed

Lines changed: 72 additions & 82 deletions

File tree

src/shape/curves.js

Lines changed: 72 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function curves(p5, fn){
1212
* Bézier curves can form shapes and curves that slope gently. They're defined
1313
* by two anchor points and two control points. Bézier curves provide more
1414
* control than the spline curves created with the
15-
* <a href="#/p5/curve">curve()</a> function.
15+
* <a href="#/p5/spline">spline()</a> function.
1616
*
1717
* The first two parameters, `x1` and `y1`, set the first anchor point. The
1818
* first anchor point is where the curve starts.
@@ -462,35 +462,27 @@ function curves(p5, fn){
462462

463463
/**
464464
* Draws a curve using a Catmull-Rom spline.
465-
*
465+
*
466466
* Spline curves can form shapes and curves that slope gently. They’re like
467-
* cables that are attached to a set of points. Splines are defined by two
468-
* anchor points and two control points.
469-
*
470-
* The first two parameters, `x1` and `y1`, set the first control point. This
471-
* point isn’t drawn and can be thought of as the curve’s starting point.
472-
*
473-
* The next four parameters, `x2`, `y2`, `x3`, and `y3`, set the two anchor
474-
* points. The anchor points are the start and end points of the curve’s
475-
* visible segment.
476-
*
477-
* The seventh and eighth parameters, `x4` and `y4`, set the last control
478-
* point. This point isn’t drawn and can be thought of as the curve’s ending
479-
* point.
467+
* cables that are attached to a set of points. By default (`ends: INCLUDE`),
468+
* the curve passes through all four points you provide, in order
469+
* `p0(x1,y1)` -> `p1(x2,y2)` -> `p2(x3,y3)` -> `p3(x4,y4)`. Think of them simply as
470+
* “points on the curve.” If you switch to `ends: EXCLUDE`, p0 and p3 act
471+
* like control points and only the middle span `p1->p2` is drawn.
480472
*
481473
* Spline curves can also be drawn in 3D using WebGL mode. The 3D version of
482474
* `spline()` has twelve arguments because each point has x-, y-, and
483475
* z-coordinates.
484476
*
485477
* @method spline
486-
* @param {Number} x1 x-coordinate of the first control point.
487-
* @param {Number} y1 y-coordinate of the first control point.
488-
* @param {Number} x2 x-coordinate of the first anchor point.
489-
* @param {Number} y2 y-coordinate of the first anchor point.
490-
* @param {Number} x3 x-coordinate of the second anchor point.
491-
* @param {Number} y3 y-coordinate of the second anchor point.
492-
* @param {Number} x4 x-coordinate of the second control point.
493-
* @param {Number} y4 y-coordinate of the second control point.
478+
* @param {Number} x1 x-coordinate of point p0.
479+
* @param {Number} y1 y-coordinate of point p0.
480+
* @param {Number} x2 x-coordinate of point p1.
481+
* @param {Number} y2 y-coordinate of point p1.
482+
* @param {Number} x3 x-coordinate of point p2.
483+
* @param {Number} y3 y-coordinate of point p2.
484+
* @param {Number} x4 x-coordinate of point p3.
485+
* @param {Number} y4 y-coordinate of point p3.
494486
* @chainable
495487
*
496488
* @example
@@ -501,7 +493,7 @@ function curves(p5, fn){
501493
*
502494
* background(200);
503495
*
504-
* // Exclude the ends and skip the outer spans (p0->p1 and p2->p3) so only the middle span (p1->p2) is drawn.
496+
* // Exclude the endsskip the outer spans (p0p1 and p2p3) so only the middle span (p1p2) is drawn.
505497
* splineProperty('ends', EXCLUDE);
506498
*
507499
* // Draw a black spline curve.
@@ -510,18 +502,18 @@ function curves(p5, fn){
510502
* stroke(0);
511503
* spline(5, 26, 73, 24, 73, 61, 15, 65);
512504
*
513-
* // Draw red spline curves from the anchor points to the control points.
505+
* // Draw red spline curves from the points.
514506
* stroke(255, 0, 0);
515507
* spline(5, 26, 5, 26, 73, 24, 73, 61);
516508
* spline(73, 24, 73, 61, 15, 65, 15, 65);
517509
*
518-
* // Draw the anchor points in black.
510+
* // Draw the points in black.
519511
* strokeWeight(5);
520512
* stroke(0);
521513
* point(73, 24);
522514
* point(73, 61);
523515
*
524-
* // Draw the control points in red.
516+
* // Draw the points in red.
525517
* stroke(255, 0, 0);
526518
* point(5, 26);
527519
* point(15, 65);
@@ -550,7 +542,7 @@ function curves(p5, fn){
550542
* function draw() {
551543
* background(200);
552544
*
553-
* // Exclude the ends and skip the outer spans (p0->p1 and p2->p3) so only the middle span (p1->p2) is drawn.
545+
* // Exclude the endsskip the outer spans (p0p1 and p2p3) so only the middle span (p1p2) is drawn.
554546
* splineProperty('ends', EXCLUDE);
555547
*
556548
* // Draw a black spline curve.
@@ -559,7 +551,7 @@ function curves(p5, fn){
559551
* stroke(0);
560552
* spline(x1, y1, 73, 24, 73, 61, 15, 65);
561553
*
562-
* // Draw red spline curves from the anchor points to the control points.
554+
* // Draw red spline curves from the points.
563555
* stroke(255, 0, 0);
564556
* spline(x1, y1, x1, y1, 73, 24, 73, 61);
565557
* spline(73, 24, 73, 61, 15, 65, 15, 65);
@@ -570,25 +562,25 @@ function curves(p5, fn){
570562
* point(73, 24);
571563
* point(73, 61);
572564
*
573-
* // Draw the control points in red.
565+
* // Draw the points in red.
574566
* stroke(255, 0, 0);
575567
* point(x1, y1);
576568
* point(15, 65);
577569
* }
578570
*
579-
* // Start changing the first control point if the user clicks near it.
571+
* // Start changing the first point if the user clicks near it.
580572
* function mousePressed() {
581573
* if (dist(mouseX, mouseY, x1, y1) < 20) {
582574
* isChanging = true;
583575
* }
584576
* }
585577
*
586-
* // Stop changing the first control point when the user releases the mouse.
578+
* // Stop changing the first point when the user releases the mouse.
587579
* function mouseReleased() {
588580
* isChanging = false;
589581
* }
590582
*
591-
* // Update the first control point while the user drags the mouse.
583+
* // Update the first point while the user drags the mouse.
592584
* function mouseDragged() {
593585
* if (isChanging === true) {
594586
* x1 = mouseX;
@@ -605,7 +597,7 @@ function curves(p5, fn){
605597
*
606598
* background('skyblue');
607599
*
608-
* // Exclude the ends and skip the outer spans (p0->p1 and p2->p3) so only the middle span (p1->p2) is drawn.
600+
* // Exclude the endsskip the outer spans (p0p1 and p2p3) so only the middle span (p1p2) is drawn.
609601
* splineProperty('ends', EXCLUDE);
610602
*
611603
* // Draw the red balloon.
@@ -631,7 +623,7 @@ function curves(p5, fn){
631623
* function draw() {
632624
* background('skyblue');
633625
*
634-
* // Exclude the ends and skip the outer spans (p0->p1 and p2->p3) so only the middle span (p1->p2) is drawn.
626+
* // Exclude the endsskip the outer spans (p0p1 and p2p3) so only the middle span (p1p2) is drawn.
635627
* splineProperty('ends', EXCLUDE);
636628
*
637629
* // Rotate around the y-axis.
@@ -652,16 +644,16 @@ function curves(p5, fn){
652644
* @method spline
653645
* @param {Number} x1
654646
* @param {Number} y1
655-
* @param {Number} z1 z-coordinate of the first control point.
647+
* @param {Number} z1 z-coordinate of point p0.
656648
* @param {Number} x2
657649
* @param {Number} y2
658-
* @param {Number} z2 z-coordinate of the first anchor point.
650+
* @param {Number} z2 z-coordinate of point p1.
659651
* @param {Number} x3
660652
* @param {Number} y3
661-
* @param {Number} z3 z-coordinate of the second anchor point.
653+
* @param {Number} z3 z-coordinate of point p2.
662654
* @param {Number} x4
663655
* @param {Number} y4
664-
* @param {Number} z4 z-coordinate of the second control point.
656+
* @param {Number} z4 z-coordinate of point p3.
665657
* @chainable
666658
*/
667659
fn.spline = function(...args) {
@@ -676,30 +668,30 @@ function curves(p5, fn){
676668
/**
677669
* Calculates coordinates along a spline curve using interpolation.
678670
*
679-
* `splinePoint()` calculates coordinates along a spline curve using the
680-
* anchor and control points. It expects points in the same order as the
671+
* `splinePoint()` calculates coordinates along a spline curve using four
672+
* points p0, p1, p2, p3. It expects points in the same order as the
681673
* <a href="#/p5/spline">spline()</a> function. `splinePoint()` works one axis
682-
* at a time. Passing the anchor and control points' x-coordinates will
683-
* calculate the x-coordinate of a point on the curve. Passing the anchor and
684-
* control points' y-coordinates will calculate the y-coordinate of a point on
674+
* at a time. Passing the points' x-coordinates will
675+
* calculate the x-coordinate of a point on the curve. Passing the
676+
* points' y-coordinates will calculate the y-coordinate of a point on
685677
* the curve.
686678
*
687-
* The first parameter, `a`, is the coordinate of the first control point.
679+
* The first parameter, `a`, is the coordinate of point p0.
688680
*
689-
* The second and third parameters, `b` and `c`, are the coordinates of the
690-
* anchor points.
681+
* The second and third parameters, `b` and `c`, are the coordinates of
682+
* points p1 and p2.
691683
*
692-
* The fourth parameter, `d`, is the coordinate of the last control point.
684+
* The fourth parameter, `d`, is the coordinate of point p3.
693685
*
694-
* The fifth parameter, `t`, is the amount to interpolate along the curve. 0
695-
* is the first anchor point, 1 is the second anchor point, and 0.5 is halfway
686+
* The fifth parameter, `t`, is the amount to interpolate along the span
687+
* from p1 to p2. `t = 0` is p1, `t = 1` is p2, and `t = 0.5` is halfway
696688
* between them.
697689
*
698690
* @method splinePoint
699-
* @param {Number} a coordinate of first control point.
700-
* @param {Number} b coordinate of first anchor point.
701-
* @param {Number} c coordinate of second anchor point.
702-
* @param {Number} d coordinate of second control point.
691+
* @param {Number} a coordinate of point p0.
692+
* @param {Number} b coordinate of point p1.
693+
* @param {Number} c coordinate of point p2.
694+
* @param {Number} d coordinate of point p3.
703695
* @param {Number} t amount to interpolate between 0 and 1.
704696
* @return {Number} coordinate of a point on the curve.
705697
*
@@ -710,11 +702,11 @@ function curves(p5, fn){
710702
* createCanvas(100, 100);
711703
*
712704
* background(200);
713-
*
714-
* // Exclude the ends and skip the outer spans (p0->p1 and p2->p3) so only the middle span (p1->p2) is drawn.
705+
*
706+
* // Exclude the ends-skip the outer spans (p0p1 and p2p3) so only the middle span (p1p2) is drawn.
715707
* splineProperty('ends', EXCLUDE);
716-
*
717-
* // Set the coordinates for the curve's anchor and control points.
708+
*
709+
* // Set the coordinates for the curve's four points (p0, p1, p2, p3).
718710
* let x1 = 5;
719711
* let y1 = 26;
720712
* let x2 = 73;
@@ -761,11 +753,11 @@ function curves(p5, fn){
761753
*
762754
* function draw() {
763755
* background(200);
764-
*
765-
* // Exclude the ends and skip the outer spans (p0->p1 and p2->p3) so only the middle span (p1->p2) is drawn.
756+
*
757+
* // Exclude the ends-skip the outer spans (p0->p1 and p2->p3) so only the middle span (p1->p2) is drawn.
766758
* splineProperty('ends', EXCLUDE);
767-
*
768-
* // Set the coordinates for the curve's anchor and control points.
759+
*
760+
* // Set the coordinates for the curve's four points (p0, p1, p2, p3).
769761
* let x1 = 5;
770762
* let y1 = 26;
771763
* let x2 = 73;
@@ -791,6 +783,7 @@ function curves(p5, fn){
791783
* </code>
792784
* </div>
793785
*/
786+
794787
fn.splinePoint = function(a, b, c, d, t) {
795788
const s = this._renderer.states.splineProperties.tightness,
796789
t3 = t * t * t,
@@ -808,30 +801,27 @@ function curves(p5, fn){
808801
* Tangent lines skim the surface of a curve. A tangent line's slope equals
809802
* the curve's slope at the point where it intersects.
810803
*
811-
* `splineTangent()` calculates coordinates along a tangent line using the
812-
* spline curve's anchor and control points. It expects points in the same
813-
* order as the <a href="#/p5/spline">spline()</a> function. `splineTangent()`
814-
* works one axis at a time. Passing the anchor and control points'
815-
* x-coordinates will calculate the x-coordinate of a point on the tangent
816-
* line. Passing the anchor and control points' y-coordinates will calculate
817-
* the y-coordinate of a point on the tangent line.
804+
* `splineTangent()` calculates coordinates along a tangent line using four
805+
* points p0, p1, p2, p3. It expects points in the same order as the
806+
* <a href="#/p5/spline">spline()</a> function. `splineTangent()` works one
807+
* axis at a time.Passing the points' x-coordinates returns the x-component of
808+
* the tangent vector; passing the points' y-coordinates returns the y-component.
809+
* The first parameter, `a`, is the coordinate of point p0.
818810
*
819-
* The first parameter, `a`, is the coordinate of the first control point.
811+
* The second and third parameters, `b` and `c`, are the coordinates of
812+
* points p1 and p2.
820813
*
821-
* The second and third parameters, `b` and `c`, are the coordinates of the
822-
* anchor points.
814+
* The fourth parameter, `d`, is the coordinate of point p3.
823815
*
824-
* The fourth parameter, `d`, is the coordinate of the last control point.
825-
*
826-
* The fifth parameter, `t`, is the amount to interpolate along the curve. 0
827-
* is the first anchor point, 1 is the second anchor point, and 0.5 is halfway
816+
* The fifth parameter, `t`, is the amount to interpolate along the span
817+
* from p1 to p2. `t = 0` is p1, `t = 1` is p2, and `t = 0.5` is halfway
828818
* between them.
829819
*
830820
* @method splineTangent
831-
* @param {Number} a coordinate of first control point.
832-
* @param {Number} b coordinate of first anchor point.
833-
* @param {Number} c coordinate of second anchor point.
834-
* @param {Number} d coordinate of second control point.
821+
* @param {Number} a coordinate of point p0.
822+
* @param {Number} b coordinate of point p1.
823+
* @param {Number} c coordinate of point p2.
824+
* @param {Number} d coordinate of point p3.
835825
* @param {Number} t amount to interpolate between 0 and 1.
836826
* @return {Number} coordinate of a point on the tangent line.
837827
*
@@ -843,10 +833,10 @@ function curves(p5, fn){
843833
*
844834
* background(200);
845835
*
846-
* // Exclude the ends and skip the outer spans (p0->p1 and p2->p3) so only the middle span (p1->p2) is drawn.
836+
* // Exclude the endsskip the outer spans (p0p1 and p2p3) so only the middle span (p1p2) is drawn.
847837
* splineProperty('ends', EXCLUDE);
848838
*
849-
* // Set the coordinates for the curve's anchor and control points.
839+
* // Set the coordinates for the curve's four points (p0, p1, p2, p3).
850840
* let x1 = 5;
851841
* let y1 = 26;
852842
* let x2 = 73;

0 commit comments

Comments
 (0)