Skip to content

Commit

Permalink
fix #6485 Refactor ellipse drawing logic in p5.Renderer2D.js
Browse files Browse the repository at this point in the history
  • Loading branch information
tuminzee committed Oct 26, 2023
1 parent cdf8d91 commit b7a5e57
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions src/core/p5.Renderer2D.js
Original file line number Diff line number Diff line change
Expand Up @@ -621,24 +621,19 @@ class Renderer2D extends p5.Renderer{
return this;
}
}
const kappa = 0.5522847498,
// control point offset horizontal
ox = w / 2 * kappa,
// control point offset vertical
oy = h / 2 * kappa,
// x-end
xe = x + w,
// y-end
ye = y + h,
// x-middle
xm = x + w / 2,
ym = y + h / 2; // y-middle
const xm = x + w / 2, // x-middle
ym = y + h / 2, // y-middle
radiusX = w / 2,
radiusY = h / 2;
if (!this._clipping) ctx.beginPath();
ctx.moveTo(x, ym);
ctx.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y);
ctx.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym);
ctx.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye);
ctx.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym);
// ctx.moveTo(x, y);
// ctx.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y);
// ctx.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym);
// ctx.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye);
// ctx.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym);

this.drawingContext.ellipse(xm, ym,radiusX, radiusY, 0, 0, 2 * Math.PI);

if (!this._clipping && doFill) {
ctx.fill();
}
Expand Down

0 comments on commit b7a5e57

Please sign in to comment.