Skip to content

Commit

Permalink
Add strokeCircle, fillCircle and rectCenteredAt
Browse files Browse the repository at this point in the history
  • Loading branch information
tillarnold committed Feb 16, 2018
1 parent 1b1ee59 commit 9872bf0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ Clears the canvas. If you have applied any transforms to the context this may no
### l.circle(x, y, r)
Draws a path in form of a circle at `x`/`y` with a radius of `r`.

### l.strokeCircle(x, y, r)
Strokes a circle at `x`/`y` with a radius of `r`.

### l.fillCircle(x, y, r)
Fills a circle at `x`/`y` with a radius of `r`.

### l.rotateContextAt(x, y, r)
Rotates the context at `x`/`y` by `r` radians.

Expand All @@ -119,6 +125,9 @@ Resets all the transforms.
### l.clearWithTransforms()
Clears the canvas event if there have been transforms applied. The tansforms are preserved.

### l.rectCenteredAt(x, y, w, h)
Draws a path of a rectangle centered at `x`/`y` with a widht of `w` and a hight of `h`.

### l.fillRectCenteredAt(x, y, w, h)
Fills a rectangle centered at `x`/`y` with a widht of `w` and a hight of `h`.

Expand Down
13 changes: 13 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ Leinwand.prototype.circle = function cirlce(x, y, r) {
return this.arc(x, y, r, 0, 2 * Math.PI, false);
};

Leinwand.prototype.strokeCircle = function strokeCircle(x, y, r) {
return this.beginPath().circle(x, y, r).closePath().stroke();
};

Leinwand.prototype.fillCircle = function fillCircle(x, y, r) {
return this.beginPath().circle(x, y, r).closePath().fill();
};

Leinwand.prototype.rotateContextAt = function rotateContextAt(x, y, r) {
return this
.translate(x, y)
Expand All @@ -135,6 +143,11 @@ Leinwand.prototype.clearWithTransforms = function clearWithTransforms() {
.restore();
};

Leinwand.prototype.rectCenteredAt = function rectCenteredAt(x, y, w, h) {
return this
.rect(x - w / 2, y - h / 2, w, h);
};

Leinwand.prototype.fillRectCenteredAt = function fillRectCenteredAt(x, y, w, h) {
return this
.fillRect(x - w / 2, y - h / 2, w, h);
Expand Down
6 changes: 2 additions & 4 deletions test/beefy.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ img.onload = () => {
.closePath()
.fill()
.stroke()
.beginPath()
.fillStyle('blue')
.circle(50, 50, 40)
.fill()
.stroke()
.fillCircle(50, 50, 40)
.strokeCircle(50, 50, 40)
.fillRect(200, 200, 100, 100)
.rotateContextAt(250, 250, Math.PI / 4)
.fillRect(200, 200, 100, 100)
Expand Down

0 comments on commit 9872bf0

Please sign in to comment.