kopia lustrzana https://github.com/backface/turtlestitch
fix dst header and fileencoding
rodzic
b0ebf61f40
commit
f9a9cc9c36
|
@ -35,6 +35,8 @@ TurtleShepherd.prototype.clear = function() {
|
||||||
this.maxY = 0;
|
this.maxY = 0;
|
||||||
this.initX = 0;
|
this.initX = 0;
|
||||||
this.initY = 0;
|
this.initY = 0;
|
||||||
|
this.lastX = 0;
|
||||||
|
this.lastY = 0;
|
||||||
this.scale = 1;
|
this.scale = 1;
|
||||||
this.steps = 0;
|
this.steps = 0;
|
||||||
this.stitchCount = 0;
|
this.stitchCount = 0;
|
||||||
|
@ -223,6 +225,9 @@ TurtleShepherd.prototype.moveTo= function(x1, y1, x2, y2, penState) {
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.lastX = x2;
|
||||||
|
this.lastY = y2;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -390,6 +395,8 @@ TurtleShepherd.prototype.toEXP = function() {
|
||||||
scale = 10 / pixels_per_millimeter;
|
scale = 10 / pixels_per_millimeter;
|
||||||
lastStitch = null;
|
lastStitch = null;
|
||||||
hasFirst = false;
|
hasFirst = false;
|
||||||
|
weJustChangedColors = false;
|
||||||
|
origin = {}
|
||||||
|
|
||||||
function move(x, y) {
|
function move(x, y) {
|
||||||
y *= -1;
|
y *= -1;
|
||||||
|
@ -400,17 +407,21 @@ TurtleShepherd.prototype.toEXP = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i=0; i < this.cache.length; i++) {
|
for (var i=0; i < this.cache.length; i++) {
|
||||||
|
|
||||||
if (this.cache[i].cmd == "color" && !this.ignoreColors) {
|
if (this.cache[i].cmd == "color" && !this.ignoreColors) {
|
||||||
expArr.push(0x80);
|
expArr.push(0x80);
|
||||||
expArr.push(0x01);
|
expArr.push(0x01);
|
||||||
expArr.push(0x00);
|
expArr.push(0x00);
|
||||||
expArr.push(0x00);
|
expArr.push(0x00);
|
||||||
move(0,0);
|
weJustChangedColors = true;
|
||||||
|
|
||||||
} else if (this.cache[i].cmd == "move") {
|
} else if (this.cache[i].cmd == "move") {
|
||||||
|
|
||||||
stitch = this.cache[i];
|
stitch = this.cache[i];
|
||||||
|
|
||||||
if (!hasFirst) {
|
if (!hasFirst) {
|
||||||
|
origin.x = Math.round(stitch.x * scale);
|
||||||
|
origin.y = Math.round(stitch.y * scale);
|
||||||
if (!stitch.penDown) {
|
if (!stitch.penDown) {
|
||||||
expArr.push(0x80);
|
expArr.push(0x80);
|
||||||
expArr.push(0x04);
|
expArr.push(0x04);
|
||||||
|
@ -421,10 +432,10 @@ TurtleShepherd.prototype.toEXP = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasFirst) {
|
if (hasFirst) {
|
||||||
x1 = Math.round(stitch.x * scale);
|
x1 = Math.round(stitch.x * scale) - origin.x;
|
||||||
y1 = -Math.round(stitch.y * scale);
|
y1 = -Math.round(stitch.y * scale) - origin.y;
|
||||||
x0 = Math.round(lastStitch.x * scale);
|
x0 = Math.round(lastStitch.x * scale) - origin.x;
|
||||||
y0 = -Math.round(lastStitch.y * scale);
|
y0 = -Math.round(lastStitch.y * scale) - origin.y;
|
||||||
|
|
||||||
sum_x = 0;
|
sum_x = 0;
|
||||||
sum_y = 0;
|
sum_y = 0;
|
||||||
|
@ -434,6 +445,15 @@ TurtleShepherd.prototype.toEXP = function() {
|
||||||
if (!lastStitch.penDown)
|
if (!lastStitch.penDown)
|
||||||
move(0,0);
|
move(0,0);
|
||||||
|
|
||||||
|
if (weJustChangedColors) {
|
||||||
|
if (!stitch.penDown) {
|
||||||
|
expArr.push(0x80);
|
||||||
|
expArr.push(0x04);
|
||||||
|
}
|
||||||
|
move(0,0);
|
||||||
|
weJustChangedColors = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (dsteps <= 1) {
|
if (dsteps <= 1) {
|
||||||
if (!stitch.penDown) {
|
if (!stitch.penDown) {
|
||||||
expArr.push(0x80);
|
expArr.push(0x80);
|
||||||
|
@ -606,7 +626,6 @@ TurtleShepherd.prototype.toDST = function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//expArr.push(0x0A);
|
|
||||||
expArr.push(0x0d);
|
expArr.push(0x0d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -628,43 +647,34 @@ TurtleShepherd.prototype.toDST = function() {
|
||||||
writeHeader("+Y:" + pad(Math.round(exty1 / this.pixels_per_millimeter) * 10, 5), 9); //Math.round(this.getMetricHeight()*10), 9);
|
writeHeader("+Y:" + pad(Math.round(exty1 / this.pixels_per_millimeter) * 10, 5), 9); //Math.round(this.getMetricHeight()*10), 9);
|
||||||
writeHeader("-Y:" + pad(Math.abs(Math.round(exty2 / this.pixels_per_millimeter)) * 10, 5), 9);
|
writeHeader("-Y:" + pad(Math.abs(Math.round(exty2 / this.pixels_per_millimeter)) * 10, 5), 9);
|
||||||
|
|
||||||
needle_end_x = 0;
|
|
||||||
needle_end_y = 0;
|
var needle_end_x = this.lastX - this.initX;
|
||||||
for (i=0; i < this.cache.length; i++) {
|
var needle_end_y = this.lastY - this.initY;
|
||||||
if (this.cache[i].cmd == "move")
|
|
||||||
needle_end_x = this.cache[i].x;
|
|
||||||
needle_end_y = this.cache[i].y;
|
|
||||||
}
|
|
||||||
|
|
||||||
needle_end_x = needle_end_x - this.initX;
|
|
||||||
needle_end_y = needle_end_y - this.initY;
|
|
||||||
|
|
||||||
console.log(pad(needle_end_x,5), needle_end_y);
|
console.log(pad(needle_end_x,5), needle_end_y);
|
||||||
|
|
||||||
|
|
||||||
writeHeader("AX:" + pad(Math.round(needle_end_x / this.pixels_per_millimeter) * 10, 6), 10);
|
writeHeader("AX:" + pad(Math.round(needle_end_x / this.pixels_per_millimeter) * 10, 6), 10);
|
||||||
writeHeader("AY:" + pad(Math.round(needle_end_y / this.pixels_per_millimeter) * 10, 6), 10);
|
writeHeader("AY:" + pad(Math.round(needle_end_y / this.pixels_per_millimeter) * 10, 6), 10);
|
||||||
writeHeader("MX:", 10);
|
writeHeader("MX:", 10);
|
||||||
writeHeader("MY:", 10);
|
writeHeader("MY:", 10);
|
||||||
writeHeader("PD:", 10);
|
writeHeader("PD:", 10);
|
||||||
|
|
||||||
// extented header goes here
|
// extented header would go here
|
||||||
// "AU:%s\r" % author)
|
// "AU:%s\r" % author)
|
||||||
// "CP:%s\r" % meta_copyright)
|
// "CP:%s\r" % meta_copyright)
|
||||||
// "TC:%s,%s,%s\r" % (thread.hex_color(), thread.description, thread.catalog_number))
|
// "TC:%s,%s,%s\r" % (thread.hex_color(), thread.description, thread.catalog_number))
|
||||||
|
|
||||||
|
|
||||||
// end of header data
|
// end of header data
|
||||||
expArr.push(0x1a);
|
expArr.push(0x1a);
|
||||||
|
|
||||||
|
// Print remaining empty header
|
||||||
// Print empty header
|
|
||||||
for (var i=0; i<387; i++) {
|
for (var i=0; i<387; i++) {
|
||||||
expArr.push(0x20);
|
expArr.push(0x20);
|
||||||
}
|
}
|
||||||
|
|
||||||
origin = {}
|
origin = {}
|
||||||
hasFirst = false;
|
hasFirst = false;
|
||||||
|
weJustChangedColors = false;
|
||||||
|
|
||||||
for (i=0; i < this.cache.length; i++) {
|
for (i=0; i < this.cache.length; i++) {
|
||||||
|
|
||||||
|
@ -672,14 +682,13 @@ TurtleShepherd.prototype.toDST = function() {
|
||||||
expArr.push(0x00);
|
expArr.push(0x00);
|
||||||
expArr.push(0x00);
|
expArr.push(0x00);
|
||||||
expArr.push(0xC3);
|
expArr.push(0xC3);
|
||||||
encodeTajimaStitch(0, 0, false);
|
weJustChangedColors = true;
|
||||||
} else if (this.cache[i].cmd == "move") {
|
} else if (this.cache[i].cmd == "move") {
|
||||||
stitch = this.cache[i];
|
stitch = this.cache[i];
|
||||||
|
|
||||||
if (!hasFirst) {
|
if (!hasFirst) { // create a stitch at origin
|
||||||
origin.x = Math.round(stitch.x * scale);
|
origin.x = Math.round(stitch.x * scale);
|
||||||
origin.y = Math.round(stitch.y * scale);
|
origin.y = Math.round(stitch.y * scale);
|
||||||
encodeTajimaStitch(0, 0, !stitch.penDown);
|
|
||||||
encodeTajimaStitch(0, 0, !stitch.penDown);
|
encodeTajimaStitch(0, 0, !stitch.penDown);
|
||||||
lastStitch = {cmd: "move", x: 0, y:0, penDown: stitch.penDown}
|
lastStitch = {cmd: "move", x: 0, y:0, penDown: stitch.penDown}
|
||||||
hasFirst = true;
|
hasFirst = true;
|
||||||
|
@ -697,6 +706,11 @@ TurtleShepherd.prototype.toDST = function() {
|
||||||
if (!lastStitch.penDown)
|
if (!lastStitch.penDown)
|
||||||
encodeTajimaStitch(0,0, false);
|
encodeTajimaStitch(0,0, false);
|
||||||
|
|
||||||
|
if (weJustChangedColors) {
|
||||||
|
encodeTajimaStitch(0, 0, !stitch.penDown);
|
||||||
|
weJustChangedColors = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (dsteps <= 1) {
|
if (dsteps <= 1) {
|
||||||
encodeTajimaStitch((x1 - x0), (y1 - y0),
|
encodeTajimaStitch((x1 - x0), (y1 - y0),
|
||||||
!stitch.penDown);
|
!stitch.penDown);
|
||||||
|
@ -728,13 +742,12 @@ TurtleShepherd.prototype.toDST = function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// end pattern
|
||||||
expArr.push(0x00);
|
expArr.push(0x00);
|
||||||
expArr.push(0x00);
|
expArr.push(0x00);
|
||||||
expArr.push(0xF3);
|
expArr.push(0xF3);
|
||||||
|
|
||||||
str = count_stitches.toString();
|
|
||||||
|
|
||||||
|
|
||||||
|
// convert
|
||||||
expUintArr = new Uint8Array(expArr.length);
|
expUintArr = new Uint8Array(expArr.length);
|
||||||
for (i=0;i<expArr.length;i++) {
|
for (i=0;i<expArr.length;i++) {
|
||||||
expUintArr[i] = Math.round(expArr[i]);
|
expUintArr[i] = Math.round(expArr[i]);
|
||||||
|
|
Ładowanie…
Reference in New Issue