@@ -486,6 +486,29 @@ function curves(p5, fn){
486486 * @chainable
487487 *
488488 * @example
489+ *
490+ * <div>
491+ * <code>
492+ * * function setup() {
493+ * createCanvas(200, 200);
494+ * background(240);
495+ * noFill();
496+ *
497+ * stroke(0);
498+ * strokeWeight(2);
499+ * spline(40, 60, 100, 40, 120, 120, 60, 140);
500+ *
501+ * strokeWeight(5);
502+ * point(40, 60);
503+ * point(100, 40);
504+ * point(120, 120);
505+ * point(60, 140);
506+ *
507+ * describe('A black spline passes smoothly through four points');
508+ * }
509+ * </code>
510+ * </div>
511+ *
489512 * <div>
490513 * <code>
491514 * function setup() {
@@ -703,8 +726,6 @@ function curves(p5, fn){
703726 *
704727 * background(200);
705728 *
706- * // Exclude the ends-skip the outer spans (p0→p1 and p2→p3) so only the middle span (p1→p2) is drawn.
707- * splineProperty('ends', EXCLUDE);
708729 *
709730 * // Set the coordinates for the curve's four points (p0, p1, p2, p3).
710731 * let x1 = 5;
@@ -754,9 +775,6 @@ function curves(p5, fn){
754775 * function draw() {
755776 * background(200);
756777 *
757- * // Exclude the ends-skip the outer spans (p0->p1 and p2->p3) so only the middle span (p1->p2) is drawn.
758- * splineProperty('ends', EXCLUDE);
759- *
760778 * // Set the coordinates for the curve's four points (p0, p1, p2, p3).
761779 * let x1 = 5;
762780 * let y1 = 26;
@@ -828,14 +846,54 @@ function curves(p5, fn){
828846 * @example
829847 * <div>
830848 * <code>
849+ * * function setup() {
850+ * createCanvas(220, 160);
851+ * 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.');
852+ * }
853+ *
854+ * function draw() {
855+ * background(240);
856+ *
857+ * const x1 = 15, y1 = 40;
858+ * const x2 = 90, y2 = 25;
859+ * const x3 = 95, y3 = 95;
860+ * const x4 = 30, y4 = 110;
861+ *
862+ * noFill();
863+ * stroke(0);
864+ * strokeWeight(2);
865+ * spline(x1, y1, x2, y2, x3, y3, x4, y4);
866+ *
867+ * const t = 0.5 + 0.5 * sin(frameCount * 0.03);
868+ *
869+ * const px = splinePoint(x1, x2, x3, x4, t);
870+ * const py = splinePoint(y1, y2, y3, y4, t);
871+ *
872+ * let tx = splineTangent(x1, x2, x3, x4, t);
873+ * let ty = splineTangent(y1, y2, y3, y4, t);
874+ *
875+ * const m = Math.hypot(tx, ty) || 1;
876+ * tx = (tx / m) * 16;
877+ * ty = (ty / m) * 16;
878+ *
879+ * stroke(0);
880+ * strokeWeight(2);
881+ * line(px, py, px + tx, py + ty);
882+ *
883+ * noStroke();
884+ * fill('red');
885+ * circle(px, py, 7);
886+ * }
887+ * </code>
888+ * </div>
889+ *
890+ * <div>
891+ * <code>
831892 * function setup() {
832893 * createCanvas(100, 100);
833894 *
834895 * background(200);
835896 *
836- * // Exclude the ends—skip the outer spans (p0→p1 and p2→p3) so only the middle span (p1→p2) is drawn.
837- * splineProperty('ends', EXCLUDE);
838- *
839897 * // Set the coordinates for the curve's four points (p0, p1, p2, p3).
840898 * let x1 = 5;
841899 * let y1 = 26;
0 commit comments