Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/shapes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ function addShapes(p5, fn, lifecycles) {
const oldBezierVertex = fn.bezierVertex;
const oldEndContour = fn.endContour;
const oldEndShape = fn.endShape;
const oldCurveDetail = fn.curveDetail;

lifecycles.predraw = function() {
this.splineProperty('ends', this.EXCLUDE);
Expand Down Expand Up @@ -59,6 +60,33 @@ function addShapes(p5, fn, lifecycles) {
this._renderer._currentShape.at(-1, -1).handlesClose = () => false;
oldEndShape.call(this, mode);
}

fn.curve = function(...args) {
return this.spline(...args);
}

fn.beginGeometry = function(...args) {
return this._renderer.beginGeometry(...args);
}
fn.endGeometry = function(...args) {
return this._renderer.endGeometry(...args);
}

for (const key of ['curveDetail', 'bezierDetail']) {
fn[key] = function(numPoints) {
// p5 2.0's curveDetail defined *density* while 1.x's defined *absolute number of points.*
// The only way to do a true conversion would involve updating the value dynamically based
// on the length of the curve. Since this would be complex to do as an addon, we do
// the calculation based on an approximate average curve length.
const avgLength = Math.hypot(this.width, this.height) / 3;
if (numPoints) {
const density = numPoints / avgLength;
return oldCurveDetail.call(this, density);
} else {
return oldCurveDetail.call(this) * avgLength;
}
}
}
}

if (typeof p5 !== undefined) {
Expand Down