/* TurtleShepherd turltestich's central intelligence agancy */ var camera, renderer, scene; function TurtleShepherd() { this.init(); } function TurtleShepherd(world) { this.init(); } TurtleShepherd.prototype.init = function() { this.clear(); }; TurtleShepherd.prototype.clear = function() { this.cache = []; 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.hasSteps = function() { return this.steps > 0; }; TurtleShepherd.prototype.getStepCount = function() { return this.steps; }; TurtleShepherd.prototype.getJumpCount = function() { return this.jumpCount; }; TurtleShepherd.prototype.getDimensions = function() { w= ((this.maxX - this.minX)/5).toFixed(2).toString(); h= ((this.maxY - this.minY)/5).toFixed(2).toString(); return w + " x " + h + " mm"; }; TurtleShepherd.prototype.moveTo= function(x1, y1, x2, y2, penState) { x = Math.round(x); y = Math.round(y); this.cache.push( { "cmd":"move", "x":x, "y":y, "penDown":penState, } ); if (this.steps === 0) { this.initX = x1; this.initY = y1; this.minX = x1; this.minY = y1; this.maxX = x1; this.maxY = y1; } 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.steps++; if (!penState) this.jumpCount++; }; TurtleShepherd.prototype.addColorChange= function(color) { this.cache.push( { "cmd":"color", "value":color, } ); }; TurtleShepherd.prototype.setScale = function(s) { this.scale = s; }; /* TurtleShepherd.prototype.renderGrid = function(size) { size = this.gridSize; return '' + '' + '' + '' + '\n'; }; */ TurtleShepherd.prototype.toSVG = 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 = "\n"; //svgStr += "\n"; svgStr = '\n'; } hasFirst = false; tagOpen = false; for (var i=0; i < this.cache.length; i++) { if (this.cache[i].cmd == "move") { stitch = this.cache[i]; if (!hasFirst) { if (stitch.penDown) { svgStr += '\n' ; hasFirst = true; } } else { if (this.cache[i].penDown ) { if (!this.cache[i-1].penDown ) { svgStr +=' \n' ; } } } } if (tagOpen) svgStr += '" />\n'; svgStr += '\n'; return svgStr; }; TurtleShepherd.prototype.toogleShowStitches = function() { this.showStitches = !this.showStitches; }; TurtleShepherd.prototype.getShowStitches = function() { return this.showStitches; }; TurtleShepherd.prototype.toogleShowJumpStitches = function() { this.showJumpStitches = !this.showJumpStitches; }; TurtleShepherd.prototype.getShowJumpStitches = function() { return this.showJumpStitches; }; TurtleShepherd.prototype.toogleShowGrid = function() { this.showGrid = !this.showGrid; }; TurtleShepherd.prototype.getShowGrid = function() { return this.showGrid; }; 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 = "\n"; //svgStr += "\n"; svgStr = '\n'; } hasFirst = false; tagOpen = false; prevX = this.initX; prevY = this.initY; for (var i=0; i < this.cache.length; i++) { if (this.cache[i].cmd == "move") { stitch = this.cache[i]; if (stitch.penDown || this.showJumpStitches) svgStr += '\n'; else if (this.showJumpStitches) svgStr +='" stroke-linecap="round" style="stroke:rgb(255,0,0);stroke-width:0.6;" stroke-dasharray="4 4" />\n'; if (this.showStitches) { svgStr +='\n'; } } prevX = stitch.x; prevY = stitch.y; } if (tagOpen) svgStr += '" />\n'; svgStr += '\n'; return svgStr; }; TurtleShepherd.prototype.debug_msg = function (st, clear) { o = ""; if (!clear) { o = document.getElementById("debug").innerHTML; } else { o = ""; } o = st + "
" + o; document.getElementById("debug").innerHTML = o; };