From 158154fae6d1dc283182b36e5e3529d7066aaea9 Mon Sep 17 00:00:00 2001 From: Michael Aschauer Date: Sat, 21 Jan 2017 16:50:09 +0100 Subject: [PATCH] change some debugging options --- index.html | 11 +++++++-- stitchcode/turtleShepherd.js | 45 +++++++++++++++++++++++------------- 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/index.html b/index.html index 17062cc8..864da634 100644 --- a/index.html +++ b/index.html @@ -50,6 +50,13 @@ this.world.children[0] ); if (DEBUG) turtleShepherd.debug_msg("this child has a stage " + this.world.children[0].stage ); + + if (DEBUG) { + document.getElementById("code").style.display = "block"; + document.getElementById("debug").style.display = "block"; + document.getElementById("svg2").style.display = "block"; + } + loop(); }; function loop() { @@ -75,11 +82,11 @@
+ display:none;">
diff --git a/stitchcode/turtleShepherd.js b/stitchcode/turtleShepherd.js index 82db6171..667503f9 100644 --- a/stitchcode/turtleShepherd.js +++ b/stitchcode/turtleShepherd.js @@ -47,7 +47,10 @@ TurtleShepherd.prototype.hasSteps = function() { return this.steps > 0; }; -TurtleShepherd.prototype.addMoveTo= function(x,y,penState) { +TurtleShepherd.prototype.addMoveTo= function(x, y, penState) { + + x = Math.round(x); + y = Math.round(y); this.cache.push( { "cmd":"move", @@ -73,6 +76,8 @@ TurtleShepherd.prototype.addMoveTo= function(x,y,penState) { }; TurtleShepherd.prototype.initPosition = function(x,y) { + x = Math.round(x); + y = Math.round(y); this.initX = x; this.initY = -y; if (DEBUG) this.debug_msg("init " + x + " " + y ); @@ -252,22 +257,28 @@ TurtleShepherd.prototype.getShowGrid = function() { }; TurtleShepherd.prototype.toSVG2 = function() { + tx = ((-1 * (this.w / 2) * this.scale) + (this.dx * this.scale)); + ty = ((-1 * (this.h / 2) * this.scale) + (this.dy * this.scale)); + bx = ((this.w * this.scale) + (this.dx * this.scale)); + by = ((this.h * this.scale) + (this.dy * this.scale)); + + // TODO: Panning //var svgStr = "\n"; //svgStr += "\n"; svgStr = '\n'; } hasFirst = false; @@ -279,10 +290,10 @@ TurtleShepherd.prototype.toSVG2 = function() { if (this.cache[i].cmd == "move") { stitch = this.cache[i]; if (stitch.penDown || this.showJumpStitches) - svgStr += '\n'; @@ -291,8 +302,8 @@ TurtleShepherd.prototype.toSVG2 = function() { svgStr +='" stroke-linecap="round" style="stroke:rgb(255,0,0);stroke-width:0.6;" stroke-dasharray="4 4" />\n'; if (this.showStitches) { - svgStr +='\n'; } @@ -317,6 +328,7 @@ TurtleShepherd.prototype.reRender = function(cnv) { */ // draw via canvg's drawSVF + if (cnv) { var ctx = cnv.getContext('2d'); ctx.clearRect(0, 0, cnv.width, cnv.height); @@ -324,9 +336,10 @@ TurtleShepherd.prototype.reRender = function(cnv) { } // debug options - document.getElementById("code").innerHTML = sourceSVG; - //document.getElementById("svg2").innerHTML = sourceSVG; - + if (DEBUG) { + document.getElementById("code").innerHTML = sourceSVG; + //document.getElementById("svg2").innerHTML = sourceSVG; + } // drawing alternatives - to be REMOVED: // draw via canvg - works but very slow!