@@ -16,12 +16,15 @@ var curveDetail = 20;
1616p5 . prototype . _curveTightness = 0 ;
1717
1818/**
19- * Draws a Bezier curve on the screen. These curves are defined by a series
20- * of anchor and control points. The first two parameters specify the first
21- * anchor point and the last two parameters specify the other anchor point.
22- * The middle parameters specify the control points which define the shape
23- * of the curve. Bezier curves were developed by French engineer Pierre
24- * Bezier.
19+ * Draws a cubic Bezier curve on the screen. These curves are defined by a
20+ * series of anchor and control points. The first two parameters specify
21+ * the first anchor point and the last two parameters specify the other
22+ * anchor point, which become the first and last points on the curve. The
23+ * middle parameters specify the two control points which define the shape
24+ * of the curve. Approximately speaking, control points "pull" the curve
25+ * towards them.<br /><br />Bezier curves were developed by French
26+ * automotive engineer Pierre Bezier, and are commonly used in computer
27+ * graphics to define gently sloping curves. See also curve().
2528 *
2629 * @method bezier
2730 * @param {Number } x1 x-coordinate for the first anchor point
@@ -82,11 +85,10 @@ p5.prototype.bezierDetail = function(d) {
8285} ;
8386
8487/**
85- * Calculate a point on the Bezier Curve
86- *
87- * Evaluates the Bezier at point t for points a, b, c, d.
88- * The parameter t varies between 0 and 1, a and d are points
88+ * Evaluates the Bezier at position t for points a, b, c, d.
89+ * The parameters a and d are the first and last points
8990 * on the curve, and b and c are the control points.
91+ * The final parameter t varies between 0 and 1.
9092 * This can be done once with the x coordinates and a second time
9193 * with the y coordinates to get the location of a bezier curve at t.
9294 *
@@ -96,18 +98,20 @@ p5.prototype.bezierDetail = function(d) {
9698 * @param {Number } c coordinate of second control point
9799 * @param {Number } d coordinate of second point on the curve
98100 * @param {Number } t value between 0 and 1
99- * @return {Number } the value of the Bezier at point t
101+ * @return {Number } the value of the Bezier at position t
100102 * @example
101103 * <div>
102104 * <code>
103105 * noFill();
104- * bezier(85, 20, 10, 10, 90, 90, 15, 80);
106+ * x1 = 85, x2 = 10, x3 = 90, x4 = 15;
107+ * y1 = 20, y2 = 10, y3 = 90, y4 = 80;
108+ * bezier(x1, y1, x2, y2, x3, y3, x4, y4);
105109 * fill(255);
106110 * steps = 10;
107111 * for (i = 0; i <= steps; i++) {
108112 * t = i / steps;
109- * x = bezierPoint(85, 10, 90, 15 , t);
110- * y = bezierPoint(20, 10, 90, 80 , t);
113+ * x = bezierPoint(x1, x2, x3, x4 , t);
114+ * y = bezierPoint(y1, y2, y3, y4 , t);
111115 * ellipse(x, y, 5, 5);
112116 * }
113117 * </code>
@@ -122,19 +126,18 @@ p5.prototype.bezierPoint = function(a, b, c, d, t) {
122126} ;
123127
124128/**
125- * Calculates the tangent of a point on a Bezier curve
126- *
127- * Evaluates the tangent at point t for points a, b, c, d.
128- * The parameter t varies between 0 and 1, a and d are points
129- * on the curve, and b and c are the control points
129+ * Evaluates the tangent to the Bezier at position t for points a, b, c, d.
130+ * The parameters a and d are the first and last points
131+ * on the curve, and b and c are the control points.
132+ * The final parameter t varies between 0 and 1.
130133 *
131134 * @method bezierTangent
132135 * @param {Number } a coordinate of first point on the curve
133136 * @param {Number } b coordinate of first control point
134137 * @param {Number } c coordinate of second control point
135138 * @param {Number } d coordinate of second point on the curve
136139 * @param {Number } t value between 0 and 1
137- * @return {Number } the tangent at point t
140+ * @return {Number } the tangent at position t
138141 * @example
139142 * <div>
140143 * <code>
@@ -194,11 +197,12 @@ p5.prototype.bezierTangent = function(a, b, c, d, t) {
194197} ;
195198
196199/**
197- * Draws a curved line on the screen. The first and second parameters specify
198- * the beginning control point and the last two parameters specify the ending
199- * control point. The middle parameters specify the start and stop of the
200- * curve. Longer curves can be created by putting a series of curve()
201- * functions together or using curveVertex(). An additional function called
200+ * Draws a curved line on the screen between two points, given as the
201+ * middle four parameters. The first two parameters are a control point, as
202+ * if the curve came from this point even though it's not drawn. The last
203+ * two parameters similarly describe the other control point. <br /><br />
204+ * Longer curves can be created by putting a series of curve() functions
205+ * together or using curveVertex(). An additional function called
202206 * curveTightness() provides control for the visual quality of the curve.
203207 * The curve() function is an implementation of Catmull-Rom splines.
204208 *
@@ -224,6 +228,20 @@ p5.prototype.bezierTangent = function(a, b, c, d, t) {
224228 * curve(73, 24, 73, 61, 15, 65, 15, 65);
225229 * </code>
226230 * </div>
231+ * <div>
232+ * <code>
233+ * // Define the curve points as JavaScript objects
234+ * p1 = {x: 5, y: 26}, p2 = {x: 73, y: 24}
235+ * p3 = {x: 73, y: 61}, p4 = {x: 15, y: 65}
236+ * noFill();
237+ * stroke(255, 102, 0);
238+ * curve(p1.x, p1.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y)
239+ * stroke(0);
240+ * curve(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, p4.x, p4.y)
241+ * stroke(255, 102, 0);
242+ * curve(p2.x, p2.y, p3.x, p3.y, p4.x, p4.y, p4.x, p4.y)
243+ * </code>
244+ * </div>
227245 */
228246p5 . prototype . curve = function ( x1 , y1 , x2 , y2 , x3 , y3 , x4 , y4 ) {
229247 this . _validateParameters (
@@ -304,9 +322,7 @@ p5.prototype.curveTightness = function (t) {
304322} ;
305323
306324/**
307- * Calculate a point on the Curve
308- *
309- * Evaluates the Bezier at point t for points a, b, c, d.
325+ * Evaluates the curve at position t for points a, b, c, d.
310326 * The parameter t varies between 0 and 1, a and d are points
311327 * on the curve, and b and c are the control points.
312328 * This can be done once with the x coordinates and a second time
@@ -318,7 +334,7 @@ p5.prototype.curveTightness = function (t) {
318334 * @param {Number } c coordinate of second control point
319335 * @param {Number } d coordinate of second point on the curve
320336 * @param {Number } t value between 0 and 1
321- * @return {Number } bezier value at point t
337+ * @return {Number } bezier value at position t
322338 * @example
323339 * <div>
324340 * <code>
@@ -340,7 +356,7 @@ p5.prototype.curveTightness = function (t) {
340356 * </code>
341357 * </div>
342358 */
343- p5 . prototype . curvePoint = function ( a , b , c , d , t ) {
359+ p5 . prototype . curvePoint = function ( a , b , c , d , t ) {
344360 var t3 = t * t * t ,
345361 t2 = t * t ,
346362 f1 = - 0.5 * t3 + t2 - 0.5 * t ,
@@ -351,19 +367,17 @@ p5.prototype.curvePoint = function(a, b,c, d, t) {
351367} ;
352368
353369/**
354- * Calculates the tangent of a point on a curve
355- *
356- * Evaluates the tangent at point t for points a, b, c, d.
357- * The parameter t varies between 0 and 1, a and d are points
358- * on the curve, and b and c are the control points
370+ * Evaluates the tangent to the curve at position t for points a, b, c, d.
371+ * The parameter t varies between 0 and 1, a and d are points on the curve,
372+ * and b and c are the control points
359373 *
360374 * @method curveTangent
361375 * @param {Number } a coordinate of first point on the curve
362376 * @param {Number } b coordinate of first control point
363377 * @param {Number } c coordinate of second control point
364378 * @param {Number } d coordinate of second point on the curve
365379 * @param {Number } t value between 0 and 1
366- * @return {Number } the tangent at point t
380+ * @return {Number } the tangent at position t
367381 * @example
368382 * <div>
369383 * <code>
0 commit comments