diff --git a/desktop/sources/scripts/library.js b/desktop/sources/scripts/library.js index 8145d8a..7b7d06f 100644 --- a/desktop/sources/scripts/library.js +++ b/desktop/sources/scripts/library.js @@ -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 diff --git a/desktop/sources/scripts/surface.js b/desktop/sources/scripts/surface.js index bbb3b27..206637c 100644 --- a/desktop/sources/scripts/surface.js +++ b/desktop/sources/scripts/surface.js @@ -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 + } } diff --git a/examples/arrays.lisp b/examples/archives/arrays.lisp similarity index 100% rename from examples/arrays.lisp rename to examples/archives/arrays.lisp diff --git a/examples/basics.lisp b/examples/archives/basics.lisp similarity index 100% rename from examples/basics.lisp rename to examples/archives/basics.lisp diff --git a/examples/benchmark.lisp b/examples/archives/benchmark.lisp similarity index 100% rename from examples/benchmark.lisp rename to examples/archives/benchmark.lisp diff --git a/examples/crop.lisp b/examples/archives/crop.lisp similarity index 100% rename from examples/crop.lisp rename to examples/archives/crop.lisp diff --git a/examples/dejong.lisp b/examples/archives/dejong.lisp similarity index 100% rename from examples/dejong.lisp rename to examples/archives/dejong.lisp diff --git a/examples/glitch.lisp b/examples/archives/glitch.lisp similarity index 100% rename from examples/glitch.lisp rename to examples/archives/glitch.lisp diff --git a/examples/gradient.lisp b/examples/archives/gradient.lisp similarity index 100% rename from examples/gradient.lisp rename to examples/archives/gradient.lisp diff --git a/examples/guides.lisp b/examples/archives/guides.lisp similarity index 100% rename from examples/guides.lisp rename to examples/archives/guides.lisp diff --git a/examples/import.lisp b/examples/archives/import.lisp similarity index 100% rename from examples/import.lisp rename to examples/archives/import.lisp diff --git a/examples/include.lisp b/examples/archives/include.lisp similarity index 100% rename from examples/include.lisp rename to examples/archives/include.lisp diff --git a/examples/objects.lisp b/examples/archives/objects.lisp similarity index 100% rename from examples/objects.lisp rename to examples/archives/objects.lisp diff --git a/examples/open.lisp b/examples/archives/open.lisp similarity index 100% rename from examples/open.lisp rename to examples/archives/open.lisp diff --git a/examples/pixels.lisp b/examples/archives/pixels.lisp similarity index 100% rename from examples/pixels.lisp rename to examples/archives/pixels.lisp diff --git a/examples/random.file.lisp b/examples/archives/random.file.lisp similarity index 100% rename from examples/random.file.lisp rename to examples/archives/random.file.lisp diff --git a/examples/random.lisp b/examples/archives/random.lisp similarity index 100% rename from examples/random.lisp rename to examples/archives/random.lisp diff --git a/examples/recursive.lisp b/examples/archives/recursive.lisp similarity index 100% rename from examples/recursive.lisp rename to examples/archives/recursive.lisp diff --git a/examples/resize.lisp b/examples/archives/resize.lisp similarity index 100% rename from examples/resize.lisp rename to examples/archives/resize.lisp diff --git a/examples/shapes.lisp b/examples/archives/shapes.lisp similarity index 100% rename from examples/shapes.lisp rename to examples/archives/shapes.lisp diff --git a/examples/spiral.lisp b/examples/archives/spiral.lisp similarity index 100% rename from examples/spiral.lisp rename to examples/archives/spiral.lisp diff --git a/examples/stars.lisp b/examples/archives/stars.lisp similarity index 100% rename from examples/stars.lisp rename to examples/archives/stars.lisp diff --git a/examples/svg.lisp b/examples/archives/svg.lisp similarity index 100% rename from examples/svg.lisp rename to examples/archives/svg.lisp diff --git a/examples/theme.lisp b/examples/archives/theme.lisp similarity index 100% rename from examples/theme.lisp rename to examples/archives/theme.lisp diff --git a/examples/transform.lisp b/examples/archives/transform.lisp similarity index 100% rename from examples/transform.lisp rename to examples/archives/transform.lisp diff --git a/examples/on-animate.lisp b/examples/events/on-animate.lisp similarity index 100% rename from examples/on-animate.lisp rename to examples/events/on-animate.lisp diff --git a/examples/on-mouse.lisp b/examples/events/on-mouse.lisp similarity index 100% rename from examples/on-mouse.lisp rename to examples/events/on-mouse.lisp diff --git a/examples/on-osc.lisp b/examples/events/on-osc.lisp similarity index 100% rename from examples/on-osc.lisp rename to examples/events/on-osc.lisp