RoundRectPolyfill.js 379 B

123456789101112
  1. CanvasRenderingContext2D.prototype.roundRect = function (x, y, w, h, r) {
  2. if (w < 2 * r) r = w / 2;
  3. if (h < 2 * r) r = h / 2;
  4. this.beginPath();
  5. this.moveTo(x + r, y);
  6. this.arcTo(x + w, y, x + w, y + h, r);
  7. this.arcTo(x + w, y + h, x, y + h, r);
  8. this.arcTo(x, y + h, x, y, r);
  9. this.arcTo(x, y, x + w, y, r);
  10. this.closePath();
  11. return this;
  12. }