Skip to content

Commit a9c19d8

Browse files
committed
Added bezierOrder docs
1 parent bc5e026 commit a9c19d8

File tree

1 file changed

+60
-5
lines changed

1 file changed

+60
-5
lines changed

src/shape/custom_shapes.js

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -825,12 +825,67 @@ class Shape {
825825
return name + 'Src';
826826
}
827827

828-
/*
829-
Note: Internally, #bezierOrder is stored as an array, in order to accommodate
830-
primitives including Bezier segments, Bezier triangles, and Bezier quads. For example,
831-
a segment may have #bezierOrder [m], whereas a quad may have #bezierOrder [m, n].
832-
*/
833828

829+
/**
830+
* Influences the shape of the Bézier curve segment in a custom shape.
831+
* By default, this is 3; the other possible parameter is 2. This
832+
* results in quadratic Bézier curves.
833+
*
834+
* `bezierVertex()` adds a curved segment to custom shapes. The Bézier curves
835+
* it creates are defined like those made by the
836+
* <a href="#/p5/bezier">bezier()</a> function. `bezierVertex()` must be
837+
* called between the
838+
* <a href="#/p5/beginShape">beginShape()</a> and
839+
* <a href="#/p5/endShape">endShape()</a> functions. There must be at least
840+
* one call to <a href="#/p5/vertex">bezierVertex()</a>, before
841+
* a number of `bezierVertex()` calls that is a multiple of the parameter
842+
* set by <a href="#/p5/bezierOrder">bezierOrder(...)</a> (default 3).
843+
*
844+
* Each curve of order 3 requires three calls to `bezierVertex`, so
845+
* 2 curves would need 7 calls to `bezierVertex()`:
846+
* (1 one initial anchor point, two sets of 3 curves describing the curves)
847+
* With `bezierOrder(2)`, two curves would need 5 calls: 1 + 2 + 2.
848+
*
849+
* Bézier curves can also be drawn in 3D using WebGL mode.
850+
*
851+
* Note: `bezierVertex()` won’t work when an argument is passed to
852+
* <a href="#/p5/beginShape">beginShape()</a>.
853+
*
854+
* @method bezierOrder
855+
* @param {Number} order can be either 2 or 3, by default 3
856+
*
857+
* @example
858+
* <div>
859+
* <code>
860+
* function setup() {
861+
* createCanvas(100, 100);
862+
*
863+
* background(200);
864+
*
865+
* // Style the shape.
866+
* noFill();
867+
*
868+
* // Start drawing the shape.
869+
* beginShape();
870+
*
871+
* // set the order to 2 for a quadratic Bézier curve
872+
* bezierOrder(2);
873+
*
874+
* // Add the first anchor point.
875+
* bezierVertex(30, 20);
876+
*
877+
* // Add the Bézier vertex.
878+
* bezierVertex(80, 20);
879+
* bezierVertex(50, 50);
880+
*
881+
* // Stop drawing the shape.
882+
* endShape();
883+
*
884+
* describe('A black curve drawn on a gray square. The curve starts at the top-left corner and ends at the center.');
885+
* }
886+
* </code>
887+
* </div>
888+
*/
834889
bezierOrder(...order) {
835890
this.#bezierOrder = order;
836891
}

0 commit comments

Comments
 (0)