Moving examples
This commit is contained in:
parent
a3ae0177e2
commit
39b2e558bd
@ -54,32 +54,32 @@ function Library (ronin) {
|
|||||||
|
|
||||||
// Shapes
|
// Shapes
|
||||||
|
|
||||||
this.pos = (x, y, t = 'pos') => { // Returns a position shape.
|
this.pos = (x, y) => { // Returns a position shape.
|
||||||
return { x, y, t }
|
return { x, y }
|
||||||
}
|
}
|
||||||
|
|
||||||
this.size = (w, h, t = 'size') => { // Returns a size shape.
|
this.size = (w, h) => { // Returns a size shape.
|
||||||
return { w, h, t }
|
return { w, h }
|
||||||
}
|
}
|
||||||
|
|
||||||
this.rect = (x, y, w, h, t = 'rect') => { // Returns a rect shape.
|
this.rect = (x, y, w, h) => { // Returns a rect shape.
|
||||||
return { x, y, w, h, t }
|
return { x, y, w, h }
|
||||||
}
|
}
|
||||||
|
|
||||||
this.circle = (cx, cy, r, t = 'circle') => { // Returns a circle shape.
|
this.circle = (cx, cy, r) => { // Returns a circle shape.
|
||||||
return { cx, cy, r, t }
|
return { cx, cy, r }
|
||||||
}
|
}
|
||||||
|
|
||||||
this.line = (a, b, t = 'line') => { // Returns a line shape.
|
this.line = (a, b) => { // Returns a line shape.
|
||||||
return { a, b, t }
|
return { a, b }
|
||||||
}
|
}
|
||||||
|
|
||||||
this.text = (x, y, g, s, f = 'Arial', t = 'text') => { // Returns a text shape.
|
this.text = (x, y, p, t, f = 'Arial') => { // Returns a text shape.
|
||||||
return { x, y, g, s, f, t }
|
return { x, y, p, t, f }
|
||||||
}
|
}
|
||||||
|
|
||||||
this.svg = (d, t = 'svg') => { // Returns a svg shape.
|
this.svg = (d) => { // Returns a svg shape.
|
||||||
return { d, t }
|
return { d }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
|
@ -28,10 +28,10 @@ function Surface (ronin) {
|
|||||||
this.trace(shape, context)
|
this.trace(shape, context)
|
||||||
context.lineWidth = width
|
context.lineWidth = width
|
||||||
context.strokeStyle = color
|
context.strokeStyle = color
|
||||||
if (shape.t === 'text') {
|
if (isText(shape)) {
|
||||||
context.font = `${shape.g}px ${shape.f}`
|
context.font = `${shape.p}px ${shape.f}`
|
||||||
context.strokeText(shape.s, shape.x, shape.y)
|
context.strokeText(shape.t, shape.x, shape.y)
|
||||||
} else if (shape.t === 'svg') {
|
} else if (isSvg(shape)) {
|
||||||
context.lineWidth = width
|
context.lineWidth = width
|
||||||
context.strokeStyle = color
|
context.strokeStyle = color
|
||||||
context.stroke(new Path2D(shape.d))
|
context.stroke(new Path2D(shape.d))
|
||||||
@ -47,10 +47,10 @@ function Surface (ronin) {
|
|||||||
context.beginPath()
|
context.beginPath()
|
||||||
context.fillStyle = color
|
context.fillStyle = color
|
||||||
this.trace(shape, context)
|
this.trace(shape, context)
|
||||||
if (shape.t === 'text') {
|
if (isText(shape)) {
|
||||||
context.font = `${shape.g}px ${shape.f}`
|
context.font = `${shape.g}px ${shape.f}`
|
||||||
context.fillText(shape.s, shape.x, shape.y)
|
context.fillText(shape.s, shape.x, shape.y)
|
||||||
} else if (shape.t === 'svg') {
|
} else if (isSvg(shape)) {
|
||||||
context.fillStyle = color
|
context.fillStyle = color
|
||||||
context.fill(new Path2D(shape.d))
|
context.fill(new Path2D(shape.d))
|
||||||
} else {
|
} else {
|
||||||
@ -71,6 +71,7 @@ function Surface (ronin) {
|
|||||||
// Tracers
|
// Tracers
|
||||||
|
|
||||||
this.trace = function (shape, context) {
|
this.trace = function (shape, context) {
|
||||||
|
console.log(this.findType(shape))
|
||||||
if (shape.t === 'rect') {
|
if (shape.t === 'rect') {
|
||||||
this.traceRect(shape, context)
|
this.traceRect(shape, context)
|
||||||
} else if (shape.t === 'line') {
|
} 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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user