@@ -512,6 +512,48 @@ function curves(p5, fn){
512
512
* <div>
513
513
* <code>
514
514
* function setup() {
515
+ * createCanvas(200, 200);
516
+ * background(245);
517
+ *
518
+ * // Ensure the curve includes both end spans p0->p1 and p2->p3
519
+ * splineProperty('ends', INCLUDE);
520
+ *
521
+ * // Control / anchor points
522
+ * const p0 = createVector(30, 160);
523
+ * const p1 = createVector(60, 40);
524
+ * const p2 = createVector(140, 40);
525
+ * const p3 = createVector(170, 160);
526
+ *
527
+ * // Draw the spline that passes through ALL four points (INCLUDE)
528
+ * noFill();
529
+ * stroke(0);
530
+ * strokeWeight(2);
531
+ * spline(p0.x, p0.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y);
532
+ *
533
+ * // Draw markers + labels
534
+ * fill(255);
535
+ * stroke(0);
536
+ * const r = 6;
537
+ * circle(p0.x, p0.y, r);
538
+ * circle(p1.x, p1.y, r);
539
+ * circle(p2.x, p2.y, r);
540
+ * circle(p3.x, p3.y, r);
541
+ *
542
+ * noStroke();
543
+ * fill(0);
544
+ * text('p0', p0.x - 14, p0.y + 14);
545
+ * text('p1', p1.x - 14, p1.y - 8);
546
+ * text('p2', p2.x + 4, p2.y - 8);
547
+ * text('p3', p3.x + 4, p3.y + 14);
548
+ *
549
+ * describe('A black Catmull-Rom spline passes through p0, p1, p2, p3 with endpoints included.');
550
+ * }
551
+ * </code>
552
+ * </div>
553
+ *
554
+ * <div>
555
+ * <code>
556
+ * function setup() {
515
557
* createCanvas(100, 100);
516
558
*
517
559
* background(200);
@@ -800,6 +842,68 @@ function curves(p5, fn){
800
842
* }
801
843
* </code>
802
844
* </div>
845
+ *
846
+ * <div>
847
+ * <code>
848
+ * let p0, p1, p2, p3;
849
+ *
850
+ * function setup() {
851
+ * createCanvas(200, 200);
852
+ * splineProperty('ends', INCLUDE); // make endpoints part of the curve
853
+ *
854
+ * // Four points forming a gentle arch
855
+ * p0 = createVector(30, 160);
856
+ * p1 = createVector(60, 50);
857
+ * p2 = createVector(140, 50);
858
+ * p3 = createVector(170, 160);
859
+ *
860
+ * describe('Black spline through p0–p3. A red dot marks the location at parameter t on p1->p2 using splinePoint.');
861
+ * }
862
+ *
863
+ * function draw() {
864
+ * background(245);
865
+ *
866
+ * // Draw the spline for context
867
+ * noFill();
868
+ * stroke(0);
869
+ * strokeWeight(2);
870
+ * spline(p0.x, p0.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y);
871
+ *
872
+ * // Map mouse X to t in [0, 1] (span p1->p2)
873
+ * let t = constrain(map(mouseX, 0, width, 0, 1), 0, 1);
874
+ *
875
+ * // Evaluate the curve point by axis (splinePoint works one axis at a time)
876
+ * let x = splinePoint(p0.x, p1.x, p2.x, p3.x, t);
877
+ * let y = splinePoint(p0.y, p1.y, p2.y, p3.y, t);
878
+ *
879
+ * // Marker at the evaluated position
880
+ * noStroke();
881
+ * fill('red');
882
+ * circle(x, y, 8);
883
+ *
884
+ * // Draw control/anchor points
885
+ * stroke(0);
886
+ * strokeWeight(1);
887
+ * fill(255);
888
+ * const r = 6;
889
+ * circle(p0.x, p0.y, r);
890
+ * circle(p1.x, p1.y, r);
891
+ * circle(p2.x, p2.y, r);
892
+ * circle(p3.x, p3.y, r);
893
+ *
894
+ * // Labels + UI hint
895
+ * noStroke();
896
+ * fill(20);
897
+ * textSize(10);
898
+ * text('p0', p0.x - 12, p0.y + 14);
899
+ * text('p1', p1.x - 12, p1.y - 8);
900
+ * text('p2', p2.x + 4, p2.y - 8);
901
+ * text('p3', p3.x + 4, p3.y + 14);
902
+ * text('t = ' + nf(t, 1, 2) + ' (p1→p2)', 8, 16);
903
+ * }
904
+ * </code>
905
+ * </div>
906
+ *
803
907
*/
804
908
805
909
fn . splinePoint = function ( a , b , c , d , t ) {
0 commit comments