Skip to content

Commit 8e090ea

Browse files
authored
Merge pull request #7656 from processing/shape-changes
Minor 2.0 shape changes
2 parents 214e7b3 + db5f8d9 commit 8e090ea

File tree

5 files changed

+36
-144
lines changed

5 files changed

+36
-144
lines changed

src/core/p5.Graphics.js

-3
Original file line numberDiff line numberDiff line change
@@ -573,9 +573,6 @@ class Graphics {
573573

574574
this._styles = [];
575575

576-
this._bezierDetail = 20;
577-
this._curveDetail = 20;
578-
579576
// this._colorMode = RGB;
580577
// this._colorMaxes = {
581578
// rgb: [255, 255, 255, 255],

src/core/p5.Renderer.js

+18
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,24 @@ class Renderer {
212212
this.currentShape.vertex(position, textureCoordinates);
213213
}
214214

215+
bezier(x1, y1, x2, y2, x3, y3, x4, y4) {
216+
this._pInst.beginShape();
217+
this._pInst.vertex(x1, y1);
218+
this._pInst.bezierVertex(x2, y2, x3, y3, x4, y4);
219+
this._pInst.endShape();
220+
return this;
221+
}
222+
223+
spline(x1, y1, x2, y2, x3, y3, x4, y4) {
224+
this._pInst.beginShape();
225+
this._pInst.splineVertex(x1, y1);
226+
this._pInst.splineVertex(x2, y2);
227+
this._pInst.splineVertex(x3, y3);
228+
this._pInst.splineVertex(x4, y4);
229+
this._pInst.endShape();
230+
return this;
231+
}
232+
215233
beginClip(options = {}) {
216234
if (this._clipping) {
217235
throw new Error("It looks like you're trying to clip while already in the middle of clipping. Did you forget to endClip()?");

src/core/p5.Renderer2D.js

+1-22
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ class Renderer2D extends Renderer {
264264
shape.accept(visitor);
265265
if (this._clipping) {
266266
this.clipPath.addPath(visitor.path);
267-
this.clipPath.closePath();
267+
this.clipPath.closePath();
268268
} else {
269269
if (this.states.fillColor) {
270270
this.drawingContext.fill(visitor.path);
@@ -969,27 +969,6 @@ class Renderer2D extends Renderer {
969969
}
970970
}
971971

972-
//////////////////////////////////////////////
973-
// SHAPE | Curves
974-
//////////////////////////////////////////////
975-
bezier(x1, y1, x2, y2, x3, y3, x4, y4) {
976-
this._pInst.beginShape();
977-
this._pInst.vertex(x1, y1);
978-
this._pInst.bezierVertex(x2, y2, x3, y3, x4, y4);
979-
this._pInst.endShape();
980-
return this;
981-
}
982-
983-
curve(x1, y1, x2, y2, x3, y3, x4, y4) {
984-
this._pInst.beginShape();
985-
this._pInst.splineVertex(x1, y1);
986-
this._pInst.splineVertex(x2, y2);
987-
this._pInst.splineVertex(x3, y3);
988-
this._pInst.splineVertex(x4, y4);
989-
this._pInst.endShape();
990-
return this;
991-
}
992-
993972
//////////////////////////////////////////////
994973
// TRANSFORM
995974
//////////////////////////////////////////////

src/shape/curves.js

+14-116
Original file line numberDiff line numberDiff line change
@@ -214,109 +214,6 @@ function curves(p5, fn){
214214
return this;
215215
};
216216

217-
/**
218-
* Sets the number of segments used to draw Bézier curves in WebGL mode.
219-
*
220-
* In WebGL mode, smooth shapes are drawn using many flat segments. Adding
221-
* more flat segments makes shapes appear smoother.
222-
*
223-
* The parameter, `detail`, is the number of segments to use while drawing a
224-
* Bézier curve. For example, calling `bezierDetail(5)` will use 5 segments to
225-
* draw curves with the <a href="#/p5/bezier">bezier()</a> function. By
226-
* default,`detail` is 20.
227-
*
228-
* Note: `bezierDetail()` has no effect in 2D mode.
229-
*
230-
* @method bezierDetail
231-
* @param {Number} detail number of segments to use. Defaults to 20.
232-
* @chainable
233-
*
234-
* @example
235-
* <div>
236-
* <code>
237-
* // Draw the original curve.
238-
*
239-
* function setup() {
240-
* createCanvas(100, 100);
241-
*
242-
* background(200);
243-
*
244-
* // Draw the anchor points in black.
245-
* stroke(0);
246-
* strokeWeight(5);
247-
* point(85, 20);
248-
* point(15, 80);
249-
*
250-
* // Draw the control points in red.
251-
* stroke(255, 0, 0);
252-
* point(10, 10);
253-
* point(90, 90);
254-
*
255-
* // Draw a black bezier curve.
256-
* noFill();
257-
* stroke(0);
258-
* strokeWeight(1);
259-
* bezier(85, 20, 10, 10, 90, 90, 15, 80);
260-
*
261-
* // Draw red lines from the anchor points to the control points.
262-
* stroke(255, 0, 0);
263-
* line(85, 20, 10, 10);
264-
* line(15, 80, 90, 90);
265-
*
266-
* describe(
267-
* 'A gray square with three curves. A black s-curve has two straight, red lines that extend from its ends. The endpoints of all the curves are marked with dots.'
268-
* );
269-
* }
270-
* </code>
271-
* </div>
272-
*
273-
* <div>
274-
* <code>
275-
* // Draw the curve with less detail.
276-
*
277-
* function setup() {
278-
* createCanvas(100, 100, WEBGL);
279-
*
280-
* background(200);
281-
*
282-
* // Set the curveDetail() to 5.
283-
* bezierDetail(5);
284-
*
285-
* // Draw the anchor points in black.
286-
* stroke(0);
287-
* strokeWeight(5);
288-
* point(35, -30, 0);
289-
* point(-35, 30, 0);
290-
*
291-
* // Draw the control points in red.
292-
* stroke(255, 0, 0);
293-
* point(-40, -40, 0);
294-
* point(40, 40, 0);
295-
*
296-
* // Draw a black bezier curve.
297-
* noFill();
298-
* stroke(0);
299-
* strokeWeight(1);
300-
* bezier(35, -30, 0, -40, -40, 0, 40, 40, 0, -35, 30, 0);
301-
*
302-
* // Draw red lines from the anchor points to the control points.
303-
* stroke(255, 0, 0);
304-
* line(35, -30, -40, -40);
305-
* line(-35, 30, 40, 40);
306-
*
307-
* describe(
308-
* 'A gray square with three curves. A black s-curve is drawn with jagged segments. Two straight, red lines that extend from its ends. The endpoints of all the curves are marked with dots.'
309-
* );
310-
* }
311-
* </code>
312-
* </div>
313-
*/
314-
fn.bezierDetail = function(d) {
315-
// p5._validateParameters('bezierDetail', arguments);
316-
this._bezierDetail = d;
317-
return this;
318-
};
319-
320217
/**
321218
* Calculates coordinates along a Bézier curve using interpolation.
322219
*
@@ -582,10 +479,10 @@ function curves(p5, fn){
582479
* point.
583480
*
584481
* Spline curves can also be drawn in 3D using WebGL mode. The 3D version of
585-
* `curve()` has twelve arguments because each point has x-, y-, and
482+
* `spline()` has twelve arguments because each point has x-, y-, and
586483
* z-coordinates.
587484
*
588-
* @method curve
485+
* @method spline
589486
* @param {Number} x1 x-coordinate of the first control point.
590487
* @param {Number} y1 y-coordinate of the first control point.
591488
* @param {Number} x2 x-coordinate of the first anchor point.
@@ -612,8 +509,8 @@ function curves(p5, fn){
612509
*
613510
* // Draw red spline curves from the anchor points to the control points.
614511
* stroke(255, 0, 0);
615-
* curve(5, 26, 5, 26, 73, 24, 73, 61);
616-
* curve(73, 24, 73, 61, 15, 65, 15, 65);
512+
* spline(5, 26, 5, 26, 73, 24, 73, 61);
513+
* spline(73, 24, 73, 61, 15, 65, 15, 65);
617514
*
618515
* // Draw the anchor points in black.
619516
* strokeWeight(5);
@@ -654,12 +551,12 @@ function curves(p5, fn){
654551
* noFill();
655552
* strokeWeight(1);
656553
* stroke(0);
657-
* curve(x1, y1, 73, 24, 73, 61, 15, 65);
554+
* spline(x1, y1, 73, 24, 73, 61, 15, 65);
658555
*
659556
* // Draw red spline curves from the anchor points to the control points.
660557
* stroke(255, 0, 0);
661-
* curve(x1, y1, x1, y1, 73, 24, 73, 61);
662-
* curve(73, 24, 73, 61, 15, 65, 15, 65);
558+
* spline(x1, y1, x1, y1, 73, 24, 73, 61);
559+
* spline(73, 24, 73, 61, 15, 65, 15, 65);
663560
*
664561
* // Draw the anchor points in black.
665562
* strokeWeight(5);
@@ -704,7 +601,7 @@ function curves(p5, fn){
704601
*
705602
* // Draw the red balloon.
706603
* fill('red');
707-
* curve(-150, 275, 50, 60, 50, 60, 250, 275);
604+
* spline(-150, 275, 50, 60, 50, 60, 250, 275);
708605
*
709606
* // Draw the balloon string.
710607
* line(50, 60, 50, 80);
@@ -730,7 +627,7 @@ function curves(p5, fn){
730627
*
731628
* // Draw the red balloon.
732629
* fill('red');
733-
* curve(-200, 225, 0, 0, 10, 0, 0, 10, 0, 200, 225, 0);
630+
* spline(-200, 225, 0, 0, 10, 0, 0, 10, 0, 200, 225, 0);
734631
*
735632
* // Draw the balloon string.
736633
* line(0, 10, 0, 0, 30, 0);
@@ -740,7 +637,7 @@ function curves(p5, fn){
740637
*/
741638

742639
/**
743-
* @method curve
640+
* @method spline
744641
* @param {Number} x1
745642
* @param {Number} y1
746643
* @param {Number} z1 z-coordinate of the first control point.
@@ -755,12 +652,13 @@ function curves(p5, fn){
755652
* @param {Number} z4 z-coordinate of the second control point.
756653
* @chainable
757654
*/
758-
fn.curve = function(...args) {
655+
fn.spline = function(...args) {
759656
// p5._validateParameters('curve', args);
760657

761-
if (this._renderer.states.strokeColor) {
762-
this._renderer.curve(...args);
658+
if (!this._renderer.states.strokeColor && !this._renderer.states.fillColor) {
659+
return this;
763660
}
661+
this._renderer.spline(...args);
764662

765663
return this;
766664
};

test/unit/core/curves.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ suite('Curves', function() {
5050
});
5151
});
5252

53-
suite('p5.prototype.curve', function() {
53+
suite('p5.prototype.spline', function() {
5454
test('should be a function', function() {
55-
assert.ok(mockP5Prototype.curve);
56-
assert.typeOf(mockP5Prototype.curve, 'function');
55+
assert.ok(mockP5Prototype.spline);
56+
assert.typeOf(mockP5Prototype.spline, 'function');
5757
});
5858
});
5959

0 commit comments

Comments
 (0)