diff --git a/desktop/sources/scripts/lisp.js b/desktop/sources/scripts/lisp.js index 4f864c7..07c1eee 100644 --- a/desktop/sources/scripts/lisp.js +++ b/desktop/sources/scripts/lisp.js @@ -34,7 +34,6 @@ function Lisp (input, lib) { return interpret(input[2], letContext) }, - lambda: function (input, context) { return function () { const lambdaArguments = arguments @@ -46,7 +45,6 @@ function Lisp (input, lib) { return interpret(input[2], new Context(lambdaScope, context)) } }, - if: function (input, context) { if (interpret(input[1], context)) { return interpret(input[2], context) diff --git a/desktop/sources/scripts/surface.js b/desktop/sources/scripts/surface.js index 769d004..f8db945 100644 --- a/desktop/sources/scripts/surface.js +++ b/desktop/sources/scripts/surface.js @@ -25,43 +25,8 @@ function Surface (ronin) { // Shape this.stroke = (shape, width, color) => { - if (shape.t === 'rect') { - 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') - } - } - - this.strokeRect = (rect, width, color) => { this.context.beginPath() - this.context.moveTo(rect.x, rect.y) - this.context.lineTo(rect.x + rect.w, rect.y) - this.context.lineTo(rect.x + rect.w, rect.y + rect.h) - this.context.lineTo(rect.x, rect.y + rect.h) - this.context.lineTo(rect.x, rect.y) - this.context.lineWidth = width - this.context.strokeStyle = color - this.context.stroke() - this.context.closePath() - } - - this.strokeLine = function (line, width, color) { - this.context.beginPath() - this.context.moveTo(line.a.x, line.a.y) - this.context.lineTo(line.b.x, line.b.y) - this.context.lineWidth = width - this.context.strokeStyle = color - this.context.stroke() - 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.trace(shape) this.context.lineWidth = width this.context.strokeStyle = color this.context.stroke() @@ -71,33 +36,42 @@ function Surface (ronin) { // Fill this.fill = (shape, color) => { + this.context.beginPath() + this.trace(shape) + this.context.fillStyle = color + this.context.fill() + this.context.closePath() + } + + // Tracers + + this.trace = function (shape) { if (shape.t === 'rect') { - this.fillRect(shape, color) + this.traceRect(shape) + } else if (shape.t === 'line') { + this.traceLine(shape) } else if (shape.t === 'circle') { - this.fillCircle(shape, color) + this.traceCircle(shape) } else { console.warn('Unknown type') } } - this.fillRect = (rect, color) => { - this.context.beginPath() + this.traceRect = function (rect) { this.context.moveTo(rect.x, rect.y) this.context.lineTo(rect.x + rect.w, rect.y) this.context.lineTo(rect.x + rect.w, rect.y + rect.h) this.context.lineTo(rect.x, rect.y + rect.h) this.context.lineTo(rect.x, rect.y) - this.context.fillStyle = color - this.context.fill() - this.context.closePath() } - this.fillCircle = function (circle, color) { - this.context.beginPath() + this.traceLine = function (line) { + this.context.moveTo(line.a.x, line.a.y) + this.context.lineTo(line.b.x, line.b.y) + } + + this.traceCircle = function (circle) { this.context.arc(circle.x, circle.y, circle.r, 0, 2 * Math.PI) - this.context.fillStyle = color - this.context.fill() - this.context.closePath() } // IO diff --git a/examples/shapes.lisp b/examples/shapes.lisp index 5241070..cbe07a4 100644 --- a/examples/shapes.lisp +++ b/examples/shapes.lisp @@ -1,4 +1,4 @@ ; Shapes ( - (fill (circle (div (of (frame) "w") 2) (div (of (frame) "h") 2) 100) "red")) \ No newline at end of file + (stroke (circle (div (of (frame) "w") 2) (div (of (frame) "h") 2) 100) 2 "red")) \ No newline at end of file