Created
May 22, 2012 18:11
-
-
Save Sorroko/2770657 to your computer and use it in GitHub Desktop.
Extends the Canvas Rendering context in javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CanvasRenderingContext2D.prototype.roundRect = function (x, y, w, h, r) { | |
| if (w < 2 * r) r = w / 2; | |
| if (h < 2 * r) r = h / 2; | |
| this.beginPath(); | |
| this.moveTo(x+r, y); | |
| this.arcTo(x+w, y, x+w, y+h, r); | |
| this.arcTo(x+w, y+h, x, y+h, r); | |
| this.arcTo(x, y+h, x, y, r); | |
| this.arcTo(x, y, x+w, y, r); | |
| this.closePath(); | |
| return this; //return the context | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment