kopia lustrzana https://github.com/backface/turtlestitch
add colors to SVG export
rodzic
9c68ef7c13
commit
985d711a76
|
@ -220,7 +220,7 @@ TurtleShepherd.prototype.addColorChange= function(color) {
|
||||||
r: Math.round(color.r),
|
r: Math.round(color.r),
|
||||||
g: Math.round(color.g),
|
g: Math.round(color.g),
|
||||||
b: Math.round(color.b),
|
b: Math.round(color.b),
|
||||||
a: Math.round(color.a) || 255
|
a: 255 - Math.round(color.a) || 255
|
||||||
};
|
};
|
||||||
this.newColor = c;
|
this.newColor = c;
|
||||||
};
|
};
|
||||||
|
@ -318,18 +318,17 @@ TurtleShepherd.prototype.toSVG = function() {
|
||||||
|
|
||||||
hasFirst = false;
|
hasFirst = false;
|
||||||
tagOpen = false;
|
tagOpen = false;
|
||||||
|
colorChanged = false;
|
||||||
lastStitch = null;
|
lastStitch = null;
|
||||||
color = { r:0, g:0, b:0 };
|
color = { r:0, g:0, b:0, a:255 };
|
||||||
|
|
||||||
for (var i=0; i < this.cache.length; i++) {
|
for (var i=0; i < this.cache.length; i++) {
|
||||||
if (this.cache[i].cmd == "color") {
|
if (this.cache[i].cmd == "color") {
|
||||||
/*if (tagOpen) svgStr += '" />\n';
|
color = this.cache[i].color;
|
||||||
color = {
|
colorChanged = true;
|
||||||
r: this.cache[i].color.r,
|
if (tagOpen) svgStr += '" />\n';
|
||||||
g: this.cache[i].color.g,
|
tagOpen = false;
|
||||||
b: this.cache[i].color.b
|
|
||||||
};
|
|
||||||
tagOpen = false;*/
|
|
||||||
} 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) {
|
||||||
|
@ -343,23 +342,11 @@ TurtleShepherd.prototype.toSVG = function() {
|
||||||
hasFirst = true;
|
hasFirst = true;
|
||||||
tagOpen = true;
|
tagOpen = true;
|
||||||
} else {
|
} else {
|
||||||
/* is jum
|
// do nothing
|
||||||
svgStr += '<path stroke="red" stroke-dasharray="4 4" d="M ' +
|
|
||||||
this.initX +
|
|
||||||
' ' +
|
|
||||||
this.initY +
|
|
||||||
' L ' +
|
|
||||||
(stitch.x) +
|
|
||||||
' ' +
|
|
||||||
(stitch.y) +
|
|
||||||
'" />\n' ;
|
|
||||||
*/
|
|
||||||
//hasFirst = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (stitch.penDown ) {
|
if (stitch.penDown ) {
|
||||||
if (!lastStich.penDown ) {
|
if (!lastStich.penDown || colorChanged) {
|
||||||
svgStr +=' <path fill="none" style="stroke:rgb('+
|
svgStr +=' <path fill="none" style="stroke:rgb('+
|
||||||
color.r + ',' + color.g + ',' + color.b +
|
color.r + ',' + color.g + ',' + color.b +
|
||||||
')" d="M ' +
|
')" d="M ' +
|
||||||
|
@ -376,20 +363,10 @@ TurtleShepherd.prototype.toSVG = function() {
|
||||||
' ' +
|
' ' +
|
||||||
(this.maxY - stitch.y);
|
(this.maxY - stitch.y);
|
||||||
tagOpen = true;
|
tagOpen = true;
|
||||||
|
colorChanged = false;
|
||||||
} else {
|
} else {
|
||||||
if (tagOpen) svgStr += '" />\n';
|
if (tagOpen) svgStr += '" />\n';
|
||||||
tagOpen = false;
|
tagOpen = false;
|
||||||
/* is jump
|
|
||||||
svgStr += '<path stroke="red" stroke-dasharray="4 4" d="M ' +
|
|
||||||
(this.cache[i-1].x) +
|
|
||||||
' ' +
|
|
||||||
(this.cache[i-1].y) +
|
|
||||||
' L ' +
|
|
||||||
(stitch.x) +
|
|
||||||
' ' +
|
|
||||||
(stitch.y) +
|
|
||||||
'" />\n' ;
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lastStich = stitch;
|
lastStich = stitch;
|
||||||
|
|
Ładowanie…
Reference in New Issue