Skip to content

Commit 1e76fdc

Browse files
author
Lauren McCarthy
committed
lib
2 parents 4fe5b15 + 2d7d3a8 commit 1e76fdc

File tree

3 files changed

+127
-16
lines changed

3 files changed

+127
-16
lines changed

lib/p5.js

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! p5.js v0.4.4 April 16, 2015 */
1+
/*! p5.js v0.4.4 April 24, 2015 */
22
(function (root, factory) {
33
if (typeof define === 'function' && define.amd)
44
define('p5', [], function () { return (root.returnExportsGlobal = factory());});
@@ -4966,17 +4966,66 @@ amdclean['shape2d_primitives'] = function (require, core, canvas, constants) {
49664966
}
49674967
return this;
49684968
};
4969-
p5.prototype.rect = function (a, b, c, d) {
4969+
p5.prototype.rect = function (x, y, w, h, tl, tr, br, bl) {
49704970
if (!this._doStroke && !this._doFill) {
49714971
return;
49724972
}
4973-
var vals = canvas.modeAdjust(a, b, c, d, this._rectMode);
4973+
var vals = canvas.modeAdjust(x, y, w, h, this._rectMode);
49744974
var ctx = this.drawingContext;
49754975
if (this._doStroke && ctx.lineWidth % 2 === 1) {
49764976
ctx.translate(0.5, 0.5);
49774977
}
49784978
ctx.beginPath();
4979-
ctx.rect(vals.x, vals.y, vals.w, vals.h);
4979+
if (typeof tl === 'undefined') {
4980+
ctx.rect(vals.x, vals.y, vals.w, vals.h);
4981+
} else {
4982+
if (typeof tr === 'undefined') {
4983+
tr = tl;
4984+
}
4985+
if (typeof br === 'undefined') {
4986+
br = tr;
4987+
}
4988+
if (typeof bl === 'undefined') {
4989+
bl = br;
4990+
}
4991+
var _x = vals.x;
4992+
var _y = vals.y;
4993+
var _w = vals.w;
4994+
var _h = vals.h;
4995+
var hw = _w / 2;
4996+
var hh = _h / 2;
4997+
if (_w < 2 * tl) {
4998+
tl = hw;
4999+
}
5000+
if (_h < 2 * tl) {
5001+
tl = hh;
5002+
}
5003+
if (_w < 2 * tr) {
5004+
tr = hw;
5005+
}
5006+
if (_h < 2 * tr) {
5007+
tr = hh;
5008+
}
5009+
if (_w < 2 * br) {
5010+
br = hw;
5011+
}
5012+
if (_h < 2 * br) {
5013+
br = hh;
5014+
}
5015+
if (_w < 2 * bl) {
5016+
bl = hw;
5017+
}
5018+
if (_h < 2 * bl) {
5019+
bl = hh;
5020+
}
5021+
ctx.beginPath();
5022+
ctx.moveTo(_x + tl, _y);
5023+
ctx.arcTo(_x + _w, _y, _x + _w, _y + _h, tr);
5024+
ctx.arcTo(_x + _w, _y + _h, _x, _y + _h, br);
5025+
ctx.arcTo(_x, _y + _h, _x, _y, bl);
5026+
ctx.arcTo(_x, _y, _x + _w, _y, tl);
5027+
ctx.closePath();
5028+
}
49805029
if (this._doFill) {
49815030
ctx.fill();
49825031
}

0 commit comments

Comments
 (0)