From 10b6fb31109def78e8c38059be7fc1631aa85757 Mon Sep 17 00:00:00 2001 From: tuminzee Date: Thu, 26 Oct 2023 14:23:07 +0200 Subject: [PATCH] fix #6485 Refactor ellipse drawing logic in p5.Renderer2D.js --- src/core/p5.Renderer2D.js | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/src/core/p5.Renderer2D.js b/src/core/p5.Renderer2D.js index 7935255b49..513661859f 100644 --- a/src/core/p5.Renderer2D.js +++ b/src/core/p5.Renderer2D.js @@ -621,24 +621,20 @@ 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(); }