kopia lustrzana https://github.com/backface/turtlestitch
change some debugging options
rodzic
e1f99fc587
commit
158154fae6
11
index.html
11
index.html
|
@ -50,6 +50,13 @@
|
||||||
this.world.children[0] );
|
this.world.children[0] );
|
||||||
if (DEBUG) turtleShepherd.debug_msg("this child has a stage " +
|
if (DEBUG) turtleShepherd.debug_msg("this child has a stage " +
|
||||||
this.world.children[0].stage );
|
this.world.children[0].stage );
|
||||||
|
|
||||||
|
if (DEBUG) {
|
||||||
|
document.getElementById("code").style.display = "block";
|
||||||
|
document.getElementById("debug").style.display = "block";
|
||||||
|
document.getElementById("svg2").style.display = "block";
|
||||||
|
}
|
||||||
|
|
||||||
loop();
|
loop();
|
||||||
};
|
};
|
||||||
function loop() {
|
function loop() {
|
||||||
|
@ -75,11 +82,11 @@
|
||||||
|
|
||||||
<div name="debug" id="debug" style="background:white;font-size:60%;position:absolute;
|
<div name="debug" id="debug" style="background:white;font-size:60%;position:absolute;
|
||||||
width:33%;height:20%;left:34%;bottom:0;overflow:auto;border:1px solid #c0c0c0;
|
width:33%;height:20%;left:34%;bottom:0;overflow:auto;border:1px solid #c0c0c0;
|
||||||
">
|
display:none;">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<textarea id="code" width="480" height="360" style="background:white;font-size:60%;position:absolute;
|
<textarea id="code" width="480" height="360" style="background:white;font-size:60%;position:absolute;
|
||||||
width:33%;height:20%;left:0;bottom:0;overflow:auto;border:1px solid #c0c0c0">
|
width:33%;height:20%;left:0;bottom:0;overflow:auto;border:1px solid #c0c0c;display:none">
|
||||||
</textarea>
|
</textarea>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,10 @@ TurtleShepherd.prototype.hasSteps = function() {
|
||||||
return this.steps > 0;
|
return this.steps > 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
TurtleShepherd.prototype.addMoveTo= function(x,y,penState) {
|
TurtleShepherd.prototype.addMoveTo= function(x, y, penState) {
|
||||||
|
|
||||||
|
x = Math.round(x);
|
||||||
|
y = Math.round(y);
|
||||||
this.cache.push(
|
this.cache.push(
|
||||||
{
|
{
|
||||||
"cmd":"move",
|
"cmd":"move",
|
||||||
|
@ -73,6 +76,8 @@ TurtleShepherd.prototype.addMoveTo= function(x,y,penState) {
|
||||||
};
|
};
|
||||||
|
|
||||||
TurtleShepherd.prototype.initPosition = function(x,y) {
|
TurtleShepherd.prototype.initPosition = function(x,y) {
|
||||||
|
x = Math.round(x);
|
||||||
|
y = Math.round(y);
|
||||||
this.initX = x;
|
this.initX = x;
|
||||||
this.initY = -y;
|
this.initY = -y;
|
||||||
if (DEBUG) this.debug_msg("init " + x + " " + y );
|
if (DEBUG) this.debug_msg("init " + x + " " + y );
|
||||||
|
@ -252,22 +257,28 @@ TurtleShepherd.prototype.getShowGrid = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
TurtleShepherd.prototype.toSVG2 = function() {
|
TurtleShepherd.prototype.toSVG2 = function() {
|
||||||
|
tx = ((-1 * (this.w / 2) * this.scale) + (this.dx * this.scale));
|
||||||
|
ty = ((-1 * (this.h / 2) * this.scale) + (this.dy * this.scale));
|
||||||
|
bx = ((this.w * this.scale) + (this.dx * this.scale));
|
||||||
|
by = ((this.h * this.scale) + (this.dy * this.scale));
|
||||||
|
|
||||||
|
// TODO: Panning
|
||||||
|
|
||||||
//var svgStr = "<?xml version=\"1.0\" standalone=\"no\"?>\n";
|
//var svgStr = "<?xml version=\"1.0\" standalone=\"no\"?>\n";
|
||||||
//svgStr += "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \n\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n";
|
//svgStr += "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \n\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n";
|
||||||
svgStr = '<svg width="' + (this.w) + '" height="' +this.h + '"' +
|
svgStr = '<svg width="' + (this.w) + '" height="' +this.h + '"' +
|
||||||
' viewBox="' +
|
' viewBox="' +
|
||||||
Math.round((-1 * (this.w / 2) * this.scale) + (this.dx * this.scale)) + ' ' +
|
(tx) + ' ' +
|
||||||
Math.round((-1 * (this.h / 2) * this.scale) + (this.dy * this.scale)) + ' ' +
|
(ty) + ' ' +
|
||||||
Math.round((this.w * this.scale) + (this.dx * this.scale)) + ' ' +
|
(bx) + ' ' +
|
||||||
Math.round((this.h * this.scale) + (this.dy * this.scale)) + '"\n';
|
(by) + '"\n';
|
||||||
svgStr += ' xmlns="http://www.w3.org/2000/svg" version="1.1">\n';
|
svgStr += ' xmlns="http://www.w3.org/2000/svg" version="1.1">\n';
|
||||||
svgStr += '<title>Embroidery export</title>\n';
|
svgStr += '<title>Embroidery export</title>\n';
|
||||||
|
|
||||||
if (this.showGrid) {
|
if (this.showGrid) {
|
||||||
svgStr += this.renderGrid();
|
svgStr += this.renderGrid();
|
||||||
svgStr += '<rect x="' + Math.round(-1 * this.w / 2 * this.scale) +
|
svgStr += '<rect x="' + ((-1 * (this.w / 2) * this.scale)) +
|
||||||
'" y="' + Math.round(-1 * this.h / 2 * this.scale) +
|
'" y="' + ((-1 * (this.h / 2) * this.scale)) +
|
||||||
'" width="100%" height="100%" fill="url(#grid)" />\n';
|
'" width="100%" height="100%" fill="url(#grid)" />\n';
|
||||||
}
|
}
|
||||||
hasFirst = false;
|
hasFirst = false;
|
||||||
|
@ -279,10 +290,10 @@ TurtleShepherd.prototype.toSVG2 = function() {
|
||||||
if (this.cache[i].cmd == "move") {
|
if (this.cache[i].cmd == "move") {
|
||||||
stitch = this.cache[i];
|
stitch = this.cache[i];
|
||||||
if (stitch.penDown || this.showJumpStitches)
|
if (stitch.penDown || this.showJumpStitches)
|
||||||
svgStr += '<line x1="'+ Math.round(prevX) +
|
svgStr += '<line x1="'+ (prevX) +
|
||||||
'" y1="'+ Math.round(prevY) +
|
'" y1="'+ (prevY) +
|
||||||
'" x2="' + Math.round(stitch.x) +
|
'" x2="' + (stitch.x) +
|
||||||
'" y2="' + Math.round(stitch.y);
|
'" y2="' + (stitch.y);
|
||||||
|
|
||||||
if (stitch.penDown)
|
if (stitch.penDown)
|
||||||
svgStr +='" stroke-linecap="round" style="stroke:rgb(0,0,0);stroke-width:1" />\n';
|
svgStr +='" stroke-linecap="round" style="stroke:rgb(0,0,0);stroke-width:1" />\n';
|
||||||
|
@ -291,8 +302,8 @@ TurtleShepherd.prototype.toSVG2 = function() {
|
||||||
svgStr +='" stroke-linecap="round" style="stroke:rgb(255,0,0);stroke-width:0.6;" stroke-dasharray="4 4" />\n';
|
svgStr +='" stroke-linecap="round" style="stroke:rgb(255,0,0);stroke-width:0.6;" stroke-dasharray="4 4" />\n';
|
||||||
|
|
||||||
if (this.showStitches) {
|
if (this.showStitches) {
|
||||||
svgStr +='<circle cx="'+ stitch.x +
|
svgStr +='<circle cx="'+ (stitch.x) +
|
||||||
'" cy="'+ stitch.y +
|
'" cy="'+ (stitch.y) +
|
||||||
'" r="1.8" stroke="blue" fill="blue"/>\n';
|
'" r="1.8" stroke="blue" fill="blue"/>\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,6 +328,7 @@ TurtleShepherd.prototype.reRender = function(cnv) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// draw via canvg's drawSVF
|
// draw via canvg's drawSVF
|
||||||
|
|
||||||
if (cnv) {
|
if (cnv) {
|
||||||
var ctx = cnv.getContext('2d');
|
var ctx = cnv.getContext('2d');
|
||||||
ctx.clearRect(0, 0, cnv.width, cnv.height);
|
ctx.clearRect(0, 0, cnv.width, cnv.height);
|
||||||
|
@ -324,9 +336,10 @@ TurtleShepherd.prototype.reRender = function(cnv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// debug options
|
// debug options
|
||||||
document.getElementById("code").innerHTML = sourceSVG;
|
if (DEBUG) {
|
||||||
//document.getElementById("svg2").innerHTML = sourceSVG;
|
document.getElementById("code").innerHTML = sourceSVG;
|
||||||
|
//document.getElementById("svg2").innerHTML = sourceSVG;
|
||||||
|
}
|
||||||
// drawing alternatives - to be REMOVED:
|
// drawing alternatives - to be REMOVED:
|
||||||
|
|
||||||
// draw via canvg - works but very slow!
|
// draw via canvg - works but very slow!
|
||||||
|
|
Ładowanie…
Reference in New Issue