diff --git a/desktop/sources/index.html b/desktop/sources/index.html index 6d7b129..eca0f5a 100644 --- a/desktop/sources/index.html +++ b/desktop/sources/index.html @@ -16,23 +16,17 @@ diff --git a/desktop/sources/scripts/library.js b/desktop/sources/scripts/library.js index a1fd99e..0a6f4c5 100644 --- a/desktop/sources/scripts/library.js +++ b/desktop/sources/scripts/library.js @@ -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 } } diff --git a/desktop/sources/scripts/surface.js b/desktop/sources/scripts/surface.js index 972790f..769d004 100644 --- a/desktop/sources/scripts/surface.js +++ b/desktop/sources/scripts/surface.js @@ -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) { diff --git a/examples/shapes.lisp b/examples/shapes.lisp new file mode 100644 index 0000000..5241070 --- /dev/null +++ b/examples/shapes.lisp @@ -0,0 +1,4 @@ +; Shapes + +( + (fill (circle (div (of (frame) "w") 2) (div (of (frame) "h") 2) 100) "red")) \ No newline at end of file