From f606b9be5f8f059964441275aff72b1d57b6bfdf Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Wed, 4 Jan 2017 11:25:40 -0700 Subject: [PATCH] Added rect shape --- README.md | 8 ++++++++ scripts/dotgrid.js | 20 ++++++++++++++++++-- scripts/keyboard.js | 3 ++- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 74d7e1e..699cd13 100644 --- a/README.md +++ b/README.md @@ -16,4 +16,12 @@ e EXPORT(Not working atm, just copy the DOM element) aA CLOCKWISE sS COUNTERWISE d LINE +``` + +## Shapes + +``` +z DOT +x CIRCLE +c RECT ``` \ No newline at end of file diff --git a/scripts/dotgrid.js b/scripts/dotgrid.js index 1884f85..72d2472 100644 --- a/scripts/dotgrid.js +++ b/scripts/dotgrid.js @@ -160,6 +160,8 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca this.draw_circle = function() { + if(from === null || to === null){ return; } + var s = document.createElementNS("http://www.w3.org/2000/svg", "circle"); s.setAttribute("cx",-from[0]); s.setAttribute("cy",from[1]); @@ -169,6 +171,20 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca reset(); } + this.draw_rect = function() + { + if(from === null || to === null){ return; } + + var s = document.createElementNS("http://www.w3.org/2000/svg", "rect"); + s.setAttribute("x",-from[0]); + s.setAttribute("y",from[1]); + s.setAttribute("width",Math.abs(to[0]) - Math.abs(from[0])); + s.setAttribute("height",Math.abs(to[1]) - Math.abs(from[1])); + vector_element.appendChild(s); + + reset(); + } + this.reset = function() { reset(); @@ -193,9 +209,9 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca this.export = function() { - var w = window.open('about:blank','image from canvas'); + var w = window.open('about:blank'); w.document.write("Export"); - w.document.appendChild(vector_element); + w.document.body.innerText += vector_element.outerHTML; } // Normalizers diff --git a/scripts/keyboard.js b/scripts/keyboard.js index e0b5336..167f1ed 100644 --- a/scripts/keyboard.js +++ b/scripts/keyboard.js @@ -10,10 +10,11 @@ function Keyboard() case 81 : dotgrid.reset(); break; case 87 : dotgrid.erase(); break; - case 80 : dotgrid.export(); break; + case 69 : dotgrid.export(); break; case 90 : dotgrid.draw_dot(); break; case 88 : dotgrid.draw_circle(); break; + case 67 : dotgrid.draw_rect(); break; } } }