Added the circle shape

This commit is contained in:
Devine Lu Linvega
2019-07-14 08:53:24 +09:00
parent c99ae1dad7
commit 685d70439b
4 changed files with 31 additions and 12 deletions

View File

@@ -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 }
}

View File

@@ -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) {