Added the circle shape
This commit is contained in:
@@ -78,7 +78,7 @@ function Library (ronin) {
|
||||
return arr
|
||||
}
|
||||
|
||||
// Rects
|
||||
// Shapes
|
||||
|
||||
this.pos = (x, y, t = 'pos') => {
|
||||
return { x, y }
|
||||
@@ -92,6 +92,10 @@ function Library (ronin) {
|
||||
return { x, y, w, h, t }
|
||||
}
|
||||
|
||||
this.circle = (x, y, r, t = 'circle') => {
|
||||
return { x, y, r, t }
|
||||
}
|
||||
|
||||
this.line = (a, b, t = 'line') => {
|
||||
return { a, b, t }
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@ function Surface (ronin) {
|
||||
this.strokeRect(shape, width, color)
|
||||
} else if (shape.t === 'line') {
|
||||
this.strokeLine(shape, width, color)
|
||||
} else if (shape.t === 'circle') {
|
||||
this.strokeCircle(shape, width, color)
|
||||
} else {
|
||||
console.warn('Unknown type')
|
||||
}
|
||||
@@ -57,11 +59,22 @@ function Surface (ronin) {
|
||||
this.context.closePath()
|
||||
}
|
||||
|
||||
this.strokeCircle = function (circle, width, color) {
|
||||
this.context.beginPath()
|
||||
this.context.arc(circle.x, circle.y, circle.r, 0, 2 * Math.PI)
|
||||
this.context.lineWidth = width
|
||||
this.context.strokeStyle = color
|
||||
this.context.stroke()
|
||||
this.context.closePath()
|
||||
}
|
||||
|
||||
// Fill
|
||||
|
||||
this.fill = (shape, color) => {
|
||||
if (shape.t === 'rect') {
|
||||
this.fillRect(shape, color)
|
||||
} else if (shape.t === 'circle') {
|
||||
this.fillCircle(shape, color)
|
||||
} else {
|
||||
console.warn('Unknown type')
|
||||
}
|
||||
@@ -79,6 +92,14 @@ function Surface (ronin) {
|
||||
this.context.closePath()
|
||||
}
|
||||
|
||||
this.fillCircle = function (circle, color) {
|
||||
this.context.beginPath()
|
||||
this.context.arc(circle.x, circle.y, circle.r, 0, 2 * Math.PI)
|
||||
this.context.fillStyle = color
|
||||
this.context.fill()
|
||||
this.context.closePath()
|
||||
}
|
||||
|
||||
// IO
|
||||
|
||||
this.open = function (path, scale) {
|
||||
|
||||
Reference in New Issue
Block a user