From 95b9650befcc0f0f69c15612198dbe1875b8c0f5 Mon Sep 17 00:00:00 2001 From: Michael Aschauer Date: Sun, 15 Oct 2017 06:45:26 +0200 Subject: [PATCH] density warning update --- stitchcode/gui.js | 4 ++-- stitchcode/turtleShepherd.js | 26 ++++++++++++-------------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/stitchcode/gui.js b/stitchcode/gui.js index 00fea049..a13ffd83 100644 --- a/stitchcode/gui.js +++ b/stitchcode/gui.js @@ -702,7 +702,7 @@ IDE_Morph.prototype.createStatusDisplay = function () { element.update = function () { this.text = "" + (stage.turtleShepherd.getTooLongStr()); }; - element.columns = 3; + element.columns = 2; element.newColumn = 1; elements.push(element); @@ -713,7 +713,7 @@ IDE_Morph.prototype.createStatusDisplay = function () { element.update = function () { this.text = "" + (stage.turtleShepherd.getDensityWarningStr()); }; - element.columns = 3; + element.columns = 2; element.newColumn = 2; elements.push(element); diff --git a/stitchcode/turtleShepherd.js b/stitchcode/turtleShepherd.js index fc9a41a8..7cd6a77b 100644 --- a/stitchcode/turtleShepherd.js +++ b/stitchcode/turtleShepherd.js @@ -19,6 +19,7 @@ TurtleShepherd.prototype.init = function() { this.pixels_per_millimeter = 5; this.maxLength = 121; this.calcTooLong = true; + this.densityMax = 15; }; @@ -73,17 +74,16 @@ TurtleShepherd.prototype.getTooLongCount = function() { TurtleShepherd.prototype.getTooLongStr = function() { if (this.tooLongCount > 1) - return this.tooLongCount + " are too long!" + return this.tooLongCount + " are too long! (will get clamped)" else if (this.tooLongCount == 1) - return this.tooLongCount + " is too long!" + return this.tooLongCount + " is too long! (will get clamped)" else return ""; }; - TurtleShepherd.prototype.getDensityWarningStr = function() { if (this.densityWarning) - return "Density Warning!"; + return "DENSITY WARNING!"; else return ""; }; @@ -148,13 +148,17 @@ TurtleShepherd.prototype.moveTo= function(x1, y1, x2, y2, penState) { var d = Math.round(x2) + "x" + Math.round(y2); if (this.density[d]) { this.density[d] += 1; - if (this.density[d] >= 10) + if (this.density[d] > this.densityMax) this.densityWarning = true; } else { this.density[d] = 1; } - - console.log(this.density); + if ( this.calcTooLong) { + if ( (Math.max( + Math.abs(x2 - x1), Math.abs(y2 - y1) + ) / this.pixels_per_millimeter * 10) / this.maxLength > 1) + this.tooLongCount += 1; + } } this.cache.push( { @@ -168,13 +172,7 @@ TurtleShepherd.prototype.moveTo= function(x1, y1, x2, y2, penState) { this.w = this.maxX - this.minX; this.h = this.maxY - this.minY; - if ( this.calcTooLong) { - if ( (Math.max( - Math.abs(x2 - x1), Math.abs(y2 - y1) - ) / this.pixels_per_millimeter * 10) / this.maxLength > 1 - ) - this.tooLongCount += 1; - } + if (!penState)