dev-2.0-svg
Michael Aschauer 2017-01-20 10:49:47 +01:00
rodzic aac55218f5
commit 32ddc734c0
4 zmienionych plików z 84 dodań i 41 usunięć

Wyświetl plik

@ -26,8 +26,7 @@
<script type="text/javascript" src="stitchcode/canvg/StackBlur.js"></script>
<script type="text/javascript" src="stitchcode/canvg/canvg.js"></script>
<script type="text/javascript" src="stitchcode/tstools.js"></script>
<script type="text/javascript" src="stitchcode/commandCache.js"></script>
<script type="text/javascript" src="stitchcode/turtleShepherd.js"></script>
<script type="text/javascript" src="stitchcode/turtlestitch.js"></script>
<script type="text/javascript" src="stitchcode/blocks.js"></script>
@ -64,10 +63,9 @@
border:1px solid #c0c0c0" ></div>
<div name="debug" id="debug" style="background:white;font-size:60%;position:absolute;
width:33%;height:20%;left:33%;bottom:0;overflow:auto;border:1px solid #c0c0c0;
width:33%;height:20%;left:34%;bottom:0;overflow:auto;border:1px solid #c0c0c0;
"></div>
<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"></textarea>

Wyświetl plik

@ -33,9 +33,18 @@ localize*/
modules.cloud = '2015-January-12';
// Global stuff
getBaseURL = function () {
var url = location.href; // entire url including querystring - also: window.location.href;
if (url.lastIndexOf('#') > 0) {
url = url.substring(0, url.lastIndexOf('#'));
}
url = url.substring(0, url.lastIndexOf('/'));
return url + "/";
};
var Cloud;
var SnapCloud = new Cloud(
tstools.getBaseURL()+ '../cloud'
getBaseURL()+ '../cloud'
);
// Cloud /////////////////////////////////////////////////////////////

Wyświetl plik

@ -9,7 +9,7 @@ SpriteMorph.prototype.forward = function (steps) {
if (!turtleShepherd.hasSteps())
turtleShepherd.initPosition(oldx, oldy);
turtleShepherd.addMoveTo(this.xPosition() , this.yPosition() , this.isDown);
this.reDrawTrails();
this.reRender();
};
SpriteMorph.prototype.origGotoXY = SpriteMorph.prototype.gotoXY;
@ -24,7 +24,7 @@ SpriteMorph.prototype.gotoXY = function (x, y, justMe) {
if (!turtleShepherd.hasSteps())
turtleShepherd.initPosition(oldx, oldy);
turtleShepherd.addMoveTo(this.xPosition() , this.yPosition() , this.isDown);
this.reDrawTrails();
this.reRender();
}
};
@ -32,12 +32,12 @@ SpriteMorph.prototype.origClear = SpriteMorph.prototype.clear;
SpriteMorph.prototype.clear = function () {
this.origClear();
turtleShepherd.clear();
this.reDrawTrails();
this.reRender();
};
SpriteMorph.prototype.reDrawTrails = function () {
SpriteMorph.prototype.reRender = function () {
this.parent.clearPenTrails();
reDraw(this.parent.penTrails());
turtleShepherd.reRender(this.parent.penTrails());
};
/* Stage */

Wyświetl plik

@ -1,8 +1,32 @@
/*
TurtleShepherd
turltestich's central intelligence agancy
*/
function TurtleShepherd() {
this.clear();
}
TurtleShepherd.prototype.clear = function() {
this.cache = [];
this.minX = 0;
this.minY = 0;
this.maxX = 0;
this.maxY = 0;
this.steps = 0;
this.initX = 0;
this.initY = 0;
this.w = 480;
this.h = 360;
this.scale = 1;
};
TurtleShepherd.prototype.hasSteps = function() {
return this.steps > 0;
};
TurtleShepherd.prototype.addMoveTo= function(x,y,penState) {
this.cache.push(
{
@ -12,7 +36,7 @@ TurtleShepherd.prototype.addMoveTo= function(x,y,penState) {
"penDown":penState,
}
);
if (this.count === 0) {
if (this.steps === 0) {
this.minX = x;
this.minY = y;
this.maxX = x;
@ -24,12 +48,14 @@ TurtleShepherd.prototype.addMoveTo= function(x,y,penState) {
if (y < this.minY) this.minY = y;
if (y > this.maxY) this.maxY = y;
}
this.count++;
//if (DEBUG) tstools.debug_msg("add move to" + x + " " + y + " " + penState );
this.steps++;
if (DEBUG) this.debug_msg("move to " + x + " " + y + " " + penState );
};
TurtleShepherd.prototype.hasSteps = function() {
return this.count > 0;
TurtleShepherd.prototype.initPosition = function(x,y) {
this.initX = x;
this.initY = y;
if (DEBUG) this.debug_msg("init " + x + " " + y );
};
TurtleShepherd.prototype.addColorChange= function(color) {
@ -41,40 +67,22 @@ TurtleShepherd.prototype.addColorChange= function(color) {
);
};
TurtleShepherd.prototype.clear = function() {
this.cache = [];
this.minX = 0;
this.minY = 0;
this.maxX = 0;
this.maxY = 0;
this.count = 0;
this.initX = 0;
this.initY = 0;
this.w = 480;
this.h = 360;
this.scale = 1;
};
TurtleShepherd.prototype.initPosition = function(x,y) {
this.initX = x;
this.initY = y;
};
TurtleShepherd.prototype.setScale = function(s) {
this.scale = s;
if (DEBUG) tstools.debug_msg("zoom to scale "+ s );
if (DEBUG) this.debug_msg("zoom to scale "+ s );
};
TurtleShepherd.prototype.zoomIn = function() {
this.scale += 0.1;
if (DEBUG) tstools.debug_msg("zoom to scale "+this.scale );
if (DEBUG) this.debug_msg("zoom to scale "+this.scale );
};
TurtleShepherd.prototype.zoomOut = function() {
if (this.scale > 0.15)
this.scale -= 0.1;
if (DEBUG) tstools.debug_msg("zoom to scale "+ this.scale );
if (DEBUG) this.debug_msg("zoom to scale "+ this.scale );
};
TurtleShepherd.prototype.setDimensions = function(x,y) {
@ -84,11 +92,11 @@ TurtleShepherd.prototype.setDimensions = function(x,y) {
TurtleShepherd.prototype.renderGrid = function(size=50) {
return '<defs>' +
'<pattern id="grid" width="'+size+'" height="'+size+'" patternUnits="userSpaceOnUse">' +
'<path d="M '+size+' 0 L 0 0 0 '+size+'" fill="none" stroke="gray" stroke-width="0.5"/>' +
return '<defs>\n' +
'<pattern id="grid" width="'+size+'" height="'+size+'" patternUnits="userSpaceOnUse">\n' +
'<path d="M '+size+' 0 L 0 0 0 '+size+'" fill="none" stroke="gray" stroke-width="0.5"/>\n' +
'</pattern>' +
'</defs>';
'</defs>\n';
};
TurtleShepherd.prototype.toSVG = function() {
@ -106,9 +114,11 @@ TurtleShepherd.prototype.toSVG = function() {
svgStr += this.renderGrid();
svgStr += '<rect x="' + (-1 * this.w / 2 * this.scale) +
'" y="' + (-1 * this.h / 2 * this.scale) +
'" width="100%" height="100%" fill="url(#grid)" />';
'" width="100%" height="100%" fill="url(#grid)" />\n';
hasFirst = false;
tagOpen = false;
for (var i=0; i < this.cache.length; i++) {
if (this.cache[i].cmd == "move") {
stitch = this.cache[i];
@ -169,3 +179,29 @@ TurtleShepherd.prototype.toSVG = function() {
svgStr += '</svg>\n';
return svgStr;
};
TurtleShepherd.prototype.reRender = function(cnv) {
//load a svg snippet in the canvas with id = 'svg'
canvas = document.getElementById('svg');
document.getElementById("code").innerHTML = turtleShepherd.toSVG();
document.getElementById("svg2").innerHTML = turtleShepherd.toSVG();
//canvg(document.getElementById('svg'), cmdCache.toSVG());
//canvg(cnv, cmdCache.toSVG());
//var cnv = caller.parent.penTrails();
//var ctx = cnv.getContext('2d');
//ctx.drawSvg(cmdCache.toSVG(), 0, 0, cnv.width, cnv.height);
}
TurtleShepherd.prototype.debug_msg = function (st, clear) {
o = "";
if (!clear) {
o = document.getElementById("debug").innerHTML;
} else {
o = "";
}
o = st + "<br />" + o;
document.getElementById("debug").innerHTML = o;
};