/* TurtleShepherd turltestich's embroidery intelligence agency */ function TurtleShepherd() { this.init(); } TurtleShepherd.prototype.init = function() { this.clear(); this.gridSize = 50; this.showJumpStitches = false; this.showStitches = false; this.showGrid = false; this.showTurtle = false; this.metric = true; }; TurtleShepherd.prototype.clear = function() { this.cache = []; this.w = 0; this.h = 0; this.minX = 0; this.minY = 0; this.maxX = 0; this.maxY = 0; this.initX = 0; this.initY = 0; this.scale = 1; this.steps = 0; this.stitchCount = 0; this.jumpCount = 0; }; TurtleShepherd.prototype.toggleMetric = function() { return this.metric = !this.metric; }; TurtleShepherd.prototype.setMetric = function(b) { this.metric = b; }; TurtleShepherd.prototype.isMetric = function() { return this.metric; }; TurtleShepherd.prototype.hasSteps = function() { return this.steps > 0; }; TurtleShepherd.prototype.getStepCount = function() { return this.steps; }; TurtleShepherd.prototype.getJumpCount = function() { return this.jumpCount; }; TurtleShepherd.prototype.getDimensions = function() { if (this.metric) { //c = 1; //unit = "mm"; c = 0.1 unit = "cm"; } else { c = 0.03937; unit = "in"; } w= ((this.maxX - this.minX)/5 * c).toFixed(2).toString(); h= ((this.maxY - this.minY)/5 * c).toFixed(2).toString(); return w + " x " + h + " " + unit; }; TurtleShepherd.prototype.getMetricWidth = function() { c = 0.1 return ((this.maxX - this.minX)/5 * c).toFixed(2).toString(); }; TurtleShepherd.prototype.getMetricHeight = function() { c = 0.1 return((this.maxY - this.minY)/5 * c).toFixed(2).toString(); }; TurtleShepherd.prototype.moveTo= function(x1, y1, x2, y2, penState) { x = Math.round(x); y = Math.round(y); if (this.steps === 0) { this.initX = x1; this.initY = y1; this.minX = x1; this.minY = y1; this.maxX = x1; this.maxY = y1; this.cache.push( { "cmd":"move", "x":x1, "y":y1, "penDown":penState, } ); } else { if (x2 < this.minX) this.minX = x2; if (x2 > this.maxX) this.maxX = x2; if (y2 < this.minY) this.minY = y2; if (y2 > this.maxY) this.maxY = y2; } this.cache.push( { "cmd":"move", "x":x2, "y":y2, "penDown":penState, } ); this.w = this.maxX - this.minX; this.h = this.maxY - this.minY; if (!penState) this.jumpCount++; else { this.steps++; } }; TurtleShepherd.prototype.addColorChange= function(color) { this.cache.push( { "cmd":"color", "color":{ r: Math.round(color.r), g: Math.round(color.g), b: Math.round(color.b), a: Math.round(color.a) || 0 }, } ); }; TurtleShepherd.prototype.toSVG = function() { var svgStr = "\n"; svgStr += "\n"; svgStr += '\n' ; */ //hasFirst = true; } } else { if (stitch.penDown ) { if (!lastStich.penDown ) { svgStr +=' \n'; tagOpen = false; /* is jump svgStr += '\n' ; */ } } lastStich = stitch; } } if (tagOpen) svgStr += '" />\n'; svgStr += '\n'; return svgStr; }; TurtleShepherd.prototype.toEXP = function() { var expArr = []; pixels_per_millimeter = 5; scale = 10 / pixels_per_millimeter; lastStitch = null; hasFirst = false; function move(x, y) { y *= -1; if (x<0) x = x + 256; expArr.push(Math.round(x)); if (y<0) y = y + 256; expArr.push(Math.round(y)); } for (var i=0; i < this.cache.length; i++) { if (this.cache[i].cmd == "color") { //expArr.push(0x01); //expArr.push(0x01); } else if (this.cache[i].cmd == "move") { stitch = this.cache[i]; if (hasFirst) { x1 = Math.round(stitch.x * scale); y1 = -Math.round(stitch.y * scale); x0 = Math.round(lastStitch.x * scale); y0 = -Math.round(lastStitch.y * scale); sum_x = 0; sum_y = 0; dmax = Math.max(Math.abs(x1 - x0), Math.abs(y1 - y0)); dsteps = Math.abs(dmax / 127); if (dsteps <= 1) { if (!stitch.penDown) { //ignore color //expArr.push(0x80); //expArr.push(0x04); } move(Math.round(x1 - x0), Math.round(y1 - y0)); } else { for(j=0;j 40) { b3 |= 0x04; dx -= 81; } if (dx < -40) { b3 |= 0x08; dx += 81; } if (dy > 40) { b3 |= 0x20; dy -= 81; } if (dy < -40) { b3 |= 0x10; dy += 81; } if (dx > 13) { b2 |= 0x04; dx -= 27; } if (dx < -13) { b2 |= 0x08; dx += 27; } if (dy > 13) { b2 |= 0x20; dy -= 27; } if (dy < -13) { b2 |= 0x10; dy += 27; } if (dx > 4) { b1 |= 0x04; dx -= 9; } if (dx < -4) { b1 |= 0x08; dx += 9; } if (dy > 4) { b1 |= 0x20; dy -= 9; } if (dy < -4) { b1 |= 0x10; dy += 9; } if (dx > 1) { b2 |= 0x01; dx -= 3; } if (dx < -1) { b2 |= 0x02; dx += 3; } if (dy > 1) { b2 |= 0x80; dy -= 3; } if (dy < -1) { b2 |= 0x40; dy += 3; } if (dx > 0) { b1 |= 0x01; dx -= 1; } if (dx < 0) { b1 |= 0x02; dx += 1; } if (dy > 0) { b1 |= 0x80; dy -= 1; } if (dy < 0) { b1 |= 0x40; dy += 1; } expArr.push(b1); expArr.push(b2); if (jump) { expArr.push(b3 | 0x83); } else { expArr.push(b3 | 0x03); } } function writeHeader(str, length, padWithSpace=false) { for(var i = 0; i" + o; document.getElementById("debug").innerHTML = o; };