canvas-extras
Advanced tools
Comparing version 1.0.5 to 1.0.6
const Canvas = require('canvas'); | ||
Canvas.CanvasRenderingContext2D.prototype.roundRect = function(x,y, width, height, radius) { | ||
const radians = 2 * Math.PI; | ||
Canvas.CanvasRenderingContext2D.prototype.roundRect = function(x,y, width, height, roundness) { | ||
const halfradians = (2 * Math.PI) / 2; | ||
const quarterradians = (2 * Math.PI) /4 | ||
this.arc(roundness + x, roundness + y, roundness, -quarterradians, halfradians, true) | ||
this.lineTo(x, y + height - roundness); | ||
this.arc(roundness + x, height - roundness + y, roundness, halfradians, quarterradians, true); | ||
this.lineTo(x + width - roundness, y + height); | ||
this.arc(x + width - roundness, y + height - roundness, roundness, quarterradians, 0, true); | ||
this.lineTo(x + width, y + roundness); | ||
this.arc(x + width - roundness, y + roundness, roundness, 0, -quarterradians, true); | ||
this.lineTo(x + roundness, y); | ||
} | ||
Canvas.CanvasRenderingContext2D.prototype.stadium = function(x,y, width, height) { | ||
var radius = height/2; | ||
const halfradians = (2 * Math.PI) / 2; | ||
const quarterradians = (2 * Math.PI) /4 | ||
this.arc(radius + x, radius + y, radius, -quarterradians, halfradians, true) | ||
@@ -17,8 +30,8 @@ this.lineTo(x, y + height - radius); | ||
Canvas.CanvasRenderingContext2D.prototype.progressBar = function(currentNum, maxNum, x, y, width, height, innerfill, outerfill, text) { | ||
Canvas.CanvasRenderingContext2D.prototype.progressBar = function(currentProgress, maxProgress, x, y, width, height, barFillColor, emptyFillColor, text) { | ||
this.save(); | ||
this.beginPath() | ||
if (!outerfill) outerfill = 'black'; | ||
if (!innerfill) innerfill = 'white'; | ||
radius = height/2; | ||
if (!emptyFillColor) emptyFillColor = 'black'; | ||
if (!barFillColor) barFillColor = 'white'; | ||
var radius = height/2; | ||
const halfradians = (2 * Math.PI) / 2; | ||
@@ -34,3 +47,3 @@ const quarterradians = (2 * Math.PI) /4 | ||
this.lineTo(x + radius, y); | ||
this.fillStyle = outerfill; | ||
this.fillStyle = emptyFillColor; | ||
this.fill(); | ||
@@ -40,3 +53,3 @@ this.stroke(); | ||
this.clip(); | ||
var calculateprogress = ((currentNum / maxNum) * width)+(x-width); | ||
var calculateprogress = ((currentProgress / maxProgress) * width)+(x-width); | ||
var tst = calculateprogress; | ||
@@ -52,3 +65,3 @@ this.beginPath(); | ||
this.lineTo(tst + radius, y); | ||
this.fillStyle = innerfill; | ||
this.fillStyle = barFillColor; | ||
this.fill(); | ||
@@ -55,0 +68,0 @@ this.closePath(); |
{ | ||
"name": "canvas-extras", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "Adds extra handy bits to canvas, including Progress Bars, rounded rectangles, and stadiums.", | ||
@@ -5,0 +5,0 @@ "main": "canvas-extras.js", |
@@ -34,3 +34,3 @@ canvas-extras adds extra handy bits to canvas, including Progress Bars, rounded rectangles, and stadiums. | ||
ctx.roundRect(x,y, width, height, roundness)` | ||
ctx.roundRect(x,y, width, height, roundness) | ||
@@ -37,0 +37,0 @@ ##### Example |
4834
63