Moving examples

This commit is contained in:
Devine Lu Linvega 2019-07-22 15:36:16 +09:00
parent a3ae0177e2
commit 39b2e558bd
28 changed files with 34 additions and 20 deletions

View File

@ -54,32 +54,32 @@ function Library (ronin) {
// Shapes
this.pos = (x, y, t = 'pos') => { // Returns a position shape.
return { x, y, t }
this.pos = (x, y) => { // Returns a position shape.
return { x, y }
}
this.size = (w, h, t = 'size') => { // Returns a size shape.
return { w, h, t }
this.size = (w, h) => { // Returns a size shape.
return { w, h }
}
this.rect = (x, y, w, h, t = 'rect') => { // Returns a rect shape.
return { x, y, w, h, t }
this.rect = (x, y, w, h) => { // Returns a rect shape.
return { x, y, w, h }
}
this.circle = (cx, cy, r, t = 'circle') => { // Returns a circle shape.
return { cx, cy, r, t }
this.circle = (cx, cy, r) => { // Returns a circle shape.
return { cx, cy, r }
}
this.line = (a, b, t = 'line') => { // Returns a line shape.
return { a, b, t }
this.line = (a, b) => { // Returns a line shape.
return { a, b }
}
this.text = (x, y, g, s, f = 'Arial', t = 'text') => { // Returns a text shape.
return { x, y, g, s, f, t }
this.text = (x, y, p, t, f = 'Arial') => { // Returns a text shape.
return { x, y, p, t, f }
}
this.svg = (d, t = 'svg') => { // Returns a svg shape.
return { d, t }
this.svg = (d) => { // Returns a svg shape.
return { d }
}
// Actions

View File

@ -28,10 +28,10 @@ function Surface (ronin) {
this.trace(shape, context)
context.lineWidth = width
context.strokeStyle = color
if (shape.t === 'text') {
context.font = `${shape.g}px ${shape.f}`
context.strokeText(shape.s, shape.x, shape.y)
} else if (shape.t === 'svg') {
if (isText(shape)) {
context.font = `${shape.p}px ${shape.f}`
context.strokeText(shape.t, shape.x, shape.y)
} else if (isSvg(shape)) {
context.lineWidth = width
context.strokeStyle = color
context.stroke(new Path2D(shape.d))
@ -47,10 +47,10 @@ function Surface (ronin) {
context.beginPath()
context.fillStyle = color
this.trace(shape, context)
if (shape.t === 'text') {
if (isText(shape)) {
context.font = `${shape.g}px ${shape.f}`
context.fillText(shape.s, shape.x, shape.y)
} else if (shape.t === 'svg') {
} else if (isSvg(shape)) {
context.fillStyle = color
context.fill(new Path2D(shape.d))
} else {
@ -71,6 +71,7 @@ function Surface (ronin) {
// Tracers
this.trace = function (shape, context) {
console.log(this.findType(shape))
if (shape.t === 'rect') {
this.traceRect(shape, context)
} else if (shape.t === 'line') {
@ -234,4 +235,17 @@ function Surface (ronin) {
}
})
}
function isRect (shape) {
return shape.x && shape.y && shape.w && shape.h
}
function isCircle (shape) {
return shape.cx && shape.cy && shape.r
}
function isSvg (shape) {
return shape.d
}
function isLine (shape) {
return shape.a && shape.a.x && shape.a.y && shape.b && shape.b.x && shape.b.y
}
}