Skip to content

Commit 4348e66

Browse files
committed
Spline properties and curve tightness docs
1 parent f8b6108 commit 4348e66

File tree

1 file changed

+52
-9
lines changed

1 file changed

+52
-9
lines changed

src/shape/custom_shapes.js

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,10 @@ class Shape {
894894
this._splineProperties[key] = value;
895895
}
896896

897+
/**
898+
* @method splineProperties
899+
* @param {Number} value
900+
*/
897901
splineProperties(values) {
898902
if (values) {
899903
for (const key in values) {
@@ -1680,24 +1684,63 @@ function customShapes(p5, fn) {
16801684
};
16811685

16821686
/**
1683-
* @method splineProperty
1684-
* @param {String} property
1685-
* @returns value The current value for the given property.
1686-
*/
1687-
/**
1687+
* Sets the property of a curve. For example, set tightness,
1688+
* use `splineProperty('tightness', t)`, with `t` between 0 and 1,
1689+
* at 0 as default.
1690+
*
1691+
* Spline curves are like cables that are attached to a set of points.
1692+
* Adjusting tightness adjusts how tightly the cable is
1693+
* attached to the points. The parameter, tightness, determines
1694+
* how the curve fits to the vertex points. By default,
1695+
* tightness is set to 0. Setting tightness to 1, as in
1696+
* `splineProperty('tightness', 1)`, connects the curve's points
1697+
* using straight lines. Values in the range from –5 to 5
1698+
* deform curves while leaving them recognizable.
1699+
*
16881700
* @method splineProperty
16891701
* @param {String} property
16901702
* @param value Value to set the given property to.
1703+
*
1704+
* @example
1705+
* <div>
1706+
* <code>
1707+
* // Move the mouse left and right to see the curve change.
1708+
*
1709+
* function setup() {
1710+
* createCanvas(100, 100);
1711+
* describe('A black curve forms a sideways U shape. The curve deforms as the user moves the mouse from left to right');
1712+
* }
1713+
*
1714+
* function draw() {
1715+
* background(200);
1716+
*
1717+
* // Set the curve's tightness using the mouse.
1718+
* let t = map(mouseX, 0, 100, -5, 5, true);
1719+
* splineProperty('tightness', t);
1720+
*
1721+
* // Draw the curve.
1722+
* noFill();
1723+
* beginShape();
1724+
* curveVertex(10, 26);
1725+
* curveVertex(10, 26);
1726+
* curveVertex(83, 24);
1727+
* curveVertex(83, 61);
1728+
* curveVertex(25, 65);
1729+
* curveVertex(25, 65);
1730+
* endShape();
1731+
* }
1732+
* </code>
1733+
* </div>
16911734
*/
16921735
fn.splineProperty = function(property, value) {
16931736
return this._renderer.splineProperty(property, value);
16941737
};
16951738

16961739
/**
1697-
* @method splineProperties
1698-
* @returns {Object} The current spline properties.
1699-
*/
1700-
/**
1740+
* Similar to <a href="#/p5/splineProperty">splineProperty()</a>:
1741+
* `splineProperty('tightness', t)` is the same as
1742+
* `splineProperties({'tightness': t})``
1743+
*
17011744
* @method splineProperties
17021745
* @param {Object} An object containing key-value pairs to set.
17031746
*/

0 commit comments

Comments
 (0)