From fdf3dacb4ca1042a0097a3121950eb6b3cc59b28 Mon Sep 17 00:00:00 2001 From: Michael Aschauer Date: Fri, 19 Oct 2018 16:24:02 +0200 Subject: [PATCH] change color only if it really changes --- stitchcode/turtleShepherd.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/stitchcode/turtleShepherd.js b/stitchcode/turtleShepherd.js index 1b5d9d4a..35d5d0cc 100644 --- a/stitchcode/turtleShepherd.js +++ b/stitchcode/turtleShepherd.js @@ -22,6 +22,7 @@ TurtleShepherd.prototype.init = function() { this.densityMax = 15; this.colors = []; this.newColor = false; + this.oldColor = null; }; @@ -44,6 +45,7 @@ TurtleShepherd.prototype.clear = function() { this.densityWarning = false; this.colors = []; this.newColor = false; + this.oldColor = null; }; @@ -156,6 +158,7 @@ TurtleShepherd.prototype.moveTo= function(x1, y1, x2, y2, penState) { } else { this.colors.push({r:0,g:0,b:0,a:255}); } + this.oldColor = this.colors[this.colors.length-1]; } } @@ -228,14 +231,21 @@ TurtleShepherd.prototype.addColorChange= function(color) { TurtleShepherd.prototype.pushColorChangeNow = function() { c = this.newColor; + o = this.oldColor; + + if (c.r == o.r && c.g == o.g && c.b == o.b && c.a == o.a) { + this.newColor = false; + return; + } index = this.colors.findIndex(x => (x.r == c.r && x.b == x.b && x.g == c.g && x.a == c.a) ); - console.log(index, this.newColor, this.colors); if (index < 0) { index = this.colors.push(this.newColor)-1; } + //console.log("change color to", c); + this.cache.push( { "cmd":"color", @@ -243,7 +253,9 @@ TurtleShepherd.prototype.pushColorChangeNow = function() { "thread": index } ); + this.oldColor = this.newColor; this.newColor = false; + }; /*