Skip to content

Commit f7189c0

Browse files
author
lauren mccarthy
committed
optimize drawing circle issue #331
1 parent c74db80 commit f7189c0

File tree

3 files changed

+57
-50
lines changed

3 files changed

+57
-50
lines changed

lib/p5.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! p5.js v0.3.3 August 25, 2014 */
1+
/*! p5.js v0.3.3 August 26, 2014 */
22
var shim = function (require) {
33
window.requestDraw = function () {
44
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function (callback, element) {
@@ -3929,20 +3929,24 @@ var shape2d_primitives = function (require, core, canvas, constants) {
39293929
}
39303930
return this;
39313931
};
3932-
p5.prototype.ellipse = function (x, y, width, height) {
3932+
p5.prototype.ellipse = function (x, y, w, h) {
39333933
if (!this._doStroke && !this._doFill) {
39343934
return;
39353935
}
39363936
var ctx = this.drawingContext;
3937-
var vals = canvas.modeAdjust(x, y, width, height, this._ellipseMode);
3938-
var kappa = 0.5522848, ox = vals.w / 2 * kappa, oy = vals.h / 2 * kappa, xe = vals.x + vals.w, ye = vals.y + vals.h, xm = vals.x + vals.w / 2, ym = vals.y + vals.h / 2;
3937+
var vals = canvas.modeAdjust(x, y, w, h, this._ellipseMode);
39393938
ctx.beginPath();
3940-
ctx.moveTo(vals.x, ym);
3941-
ctx.bezierCurveTo(vals.x, ym - oy, xm - ox, vals.y, xm, vals.y);
3942-
ctx.bezierCurveTo(xm + ox, vals.y, xe, ym - oy, xe, ym);
3943-
ctx.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye);
3944-
ctx.bezierCurveTo(xm - ox, ye, vals.x, ym + oy, vals.x, ym);
3945-
ctx.closePath();
3939+
if (w === h) {
3940+
ctx.arc(vals.x, vals.y, vals.w / 2, 0, 2 * Math.PI, false);
3941+
} else {
3942+
var kappa = 0.5522848, ox = vals.w / 2 * kappa, oy = vals.h / 2 * kappa, xe = vals.x + vals.w, ye = vals.y + vals.h, xm = vals.x + vals.w / 2, ym = vals.y + vals.h / 2;
3943+
ctx.moveTo(vals.x, ym);
3944+
ctx.bezierCurveTo(vals.x, ym - oy, xm - ox, vals.y, xm, vals.y);
3945+
ctx.bezierCurveTo(xm + ox, vals.y, xe, ym - oy, xe, ym);
3946+
ctx.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye);
3947+
ctx.bezierCurveTo(xm - ox, ye, vals.x, ym + oy, vals.x, ym);
3948+
ctx.closePath();
3949+
}
39463950
if (this._doFill) {
39473951
ctx.fill();
39483952
}

0 commit comments

Comments
 (0)