kopia lustrzana https://github.com/backface/turtlestitch
refactor
rodzic
b262cf2fa0
commit
aac55218f5
|
@ -60,9 +60,8 @@
|
||||||
|
|
||||||
|
|
||||||
<div id="svg2" style="background:white;font-size:60%;position:absolute;
|
<div id="svg2" style="background:white;font-size:60%;position:absolute;
|
||||||
width:480px;height:360px;left:34%;bottom:0;
|
position:absolute;right:0;bottom:0;width:480px;height:360px;
|
||||||
border:1px solid #c0c0c0;
|
border:1px solid #c0c0c0" ></div>
|
||||||
display:none" ></div>
|
|
||||||
|
|
||||||
<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:33%;bottom:0;overflow:auto;border:1px solid #c0c0c0;
|
width:33%;height:20%;left:33%;bottom:0;overflow:auto;border:1px solid #c0c0c0;
|
||||||
|
|
|
@ -6,9 +6,9 @@ SpriteMorph.prototype.forward = function (steps) {
|
||||||
oldx = this.xPosition();
|
oldx = this.xPosition();
|
||||||
oldy = this.yPosition();
|
oldy = this.yPosition();
|
||||||
this.origForward(steps);
|
this.origForward(steps);
|
||||||
if (!cmdCache.hasSteps())
|
if (!turtleShepherd.hasSteps())
|
||||||
cmdCache.initPosition(oldx, oldy);
|
turtleShepherd.initPosition(oldx, oldy);
|
||||||
cmdCache.addMoveTo(this.xPosition() , this.yPosition() , this.isDown);
|
turtleShepherd.addMoveTo(this.xPosition() , this.yPosition() , this.isDown);
|
||||||
this.reDrawTrails();
|
this.reDrawTrails();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -21,9 +21,9 @@ SpriteMorph.prototype.gotoXY = function (x, y, justMe) {
|
||||||
if ( Math.abs(this.xPosition()-oldx)<=1 && Math.abs(this.yPosition()-oldy)<=1 ) {
|
if ( Math.abs(this.xPosition()-oldx)<=1 && Math.abs(this.yPosition()-oldy)<=1 ) {
|
||||||
console.log("jump in place - don't add.");
|
console.log("jump in place - don't add.");
|
||||||
} else {
|
} else {
|
||||||
if (!cmdCache.hasSteps())
|
if (!turtleShepherd.hasSteps())
|
||||||
cmdCache.initPosition(oldx, oldy);
|
turtleShepherd.initPosition(oldx, oldy);
|
||||||
cmdCache.addMoveTo(this.xPosition() , this.yPosition() , this.isDown);
|
turtleShepherd.addMoveTo(this.xPosition() , this.yPosition() , this.isDown);
|
||||||
this.reDrawTrails();
|
this.reDrawTrails();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -31,7 +31,7 @@ SpriteMorph.prototype.gotoXY = function (x, y, justMe) {
|
||||||
SpriteMorph.prototype.origClear = SpriteMorph.prototype.clear;
|
SpriteMorph.prototype.origClear = SpriteMorph.prototype.clear;
|
||||||
SpriteMorph.prototype.clear = function () {
|
SpriteMorph.prototype.clear = function () {
|
||||||
this.origClear();
|
this.origClear();
|
||||||
cmdCache.clear();
|
turtleShepherd.clear();
|
||||||
this.reDrawTrails();
|
this.reDrawTrails();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -46,9 +46,9 @@ SpriteMorph.prototype.reDrawTrails = function () {
|
||||||
StageMorph.prototype.referencePos = null;
|
StageMorph.prototype.referencePos = null;
|
||||||
StageMorph.prototype.mouseScroll = function (y, x) {
|
StageMorph.prototype.mouseScroll = function (y, x) {
|
||||||
if (y > 0) {
|
if (y > 0) {
|
||||||
cmdCache.zoomOut();
|
turtleShepherd.zoomOut();
|
||||||
} else if (y < 0) {
|
} else if (y < 0) {
|
||||||
cmdCache.zoomIn();
|
turtleShepherd.zoomIn();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.clearPenTrails();
|
this.clearPenTrails();
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
|
|
||||||
function CommandCache() {
|
function TurtleShepherd() {
|
||||||
this.clear();
|
this.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandCache.prototype.addMoveTo= function(x,y,penState) {
|
TurtleShepherd.prototype.addMoveTo= function(x,y,penState) {
|
||||||
this.cache.push(
|
this.cache.push(
|
||||||
{
|
{
|
||||||
"cmd":"move",
|
"cmd":"move",
|
||||||
|
@ -28,11 +28,11 @@ CommandCache.prototype.addMoveTo= function(x,y,penState) {
|
||||||
//if (DEBUG) tstools.debug_msg("add move to" + x + " " + y + " " + penState );
|
//if (DEBUG) tstools.debug_msg("add move to" + x + " " + y + " " + penState );
|
||||||
};
|
};
|
||||||
|
|
||||||
CommandCache.prototype.hasSteps = function() {
|
TurtleShepherd.prototype.hasSteps = function() {
|
||||||
return this.count > 0;
|
return this.count > 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
CommandCache.prototype.addColorChange= function(color) {
|
TurtleShepherd.prototype.addColorChange= function(color) {
|
||||||
this.cache.push(
|
this.cache.push(
|
||||||
{
|
{
|
||||||
"cmd":"color",
|
"cmd":"color",
|
||||||
|
@ -41,7 +41,7 @@ CommandCache.prototype.addColorChange= function(color) {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
CommandCache.prototype.clear = function() {
|
TurtleShepherd.prototype.clear = function() {
|
||||||
this.cache = [];
|
this.cache = [];
|
||||||
this.minX = 0;
|
this.minX = 0;
|
||||||
this.minY = 0;
|
this.minY = 0;
|
||||||
|
@ -55,35 +55,35 @@ CommandCache.prototype.clear = function() {
|
||||||
this.scale = 1;
|
this.scale = 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
CommandCache.prototype.initPosition = function(x,y) {
|
TurtleShepherd.prototype.initPosition = function(x,y) {
|
||||||
this.initX = x;
|
this.initX = x;
|
||||||
this.initY = y;
|
this.initY = y;
|
||||||
};
|
};
|
||||||
|
|
||||||
CommandCache.prototype.setScale = function(s) {
|
TurtleShepherd.prototype.setScale = function(s) {
|
||||||
this.scale = s;
|
this.scale = s;
|
||||||
if (DEBUG) tstools.debug_msg("zoom to scale "+ s );
|
if (DEBUG) tstools.debug_msg("zoom to scale "+ s );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
CommandCache.prototype.zoomIn = function() {
|
TurtleShepherd.prototype.zoomIn = function() {
|
||||||
this.scale += 0.1;
|
this.scale += 0.1;
|
||||||
if (DEBUG) tstools.debug_msg("zoom to scale "+this.scale );
|
if (DEBUG) tstools.debug_msg("zoom to scale "+this.scale );
|
||||||
};
|
};
|
||||||
|
|
||||||
CommandCache.prototype.zoomOut = function() {
|
TurtleShepherd.prototype.zoomOut = function() {
|
||||||
if (this.scale > 0.15)
|
if (this.scale > 0.15)
|
||||||
this.scale -= 0.1;
|
this.scale -= 0.1;
|
||||||
if (DEBUG) tstools.debug_msg("zoom to scale "+ this.scale );
|
if (DEBUG) tstools.debug_msg("zoom to scale "+ this.scale );
|
||||||
};
|
};
|
||||||
|
|
||||||
CommandCache.prototype.setDimensions = function(x,y) {
|
TurtleShepherd.prototype.setDimensions = function(x,y) {
|
||||||
this.w = x;
|
this.w = x;
|
||||||
this.h = y;
|
this.h = y;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
CommandCache.prototype.renderGrid = function(size=50) {
|
TurtleShepherd.prototype.renderGrid = function(size=50) {
|
||||||
return '<defs>' +
|
return '<defs>' +
|
||||||
'<pattern id="grid" width="'+size+'" height="'+size+'" patternUnits="userSpaceOnUse">' +
|
'<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"/>' +
|
'<path d="M '+size+' 0 L 0 0 0 '+size+'" fill="none" stroke="gray" stroke-width="0.5"/>' +
|
||||||
|
@ -91,7 +91,7 @@ CommandCache.prototype.renderGrid = function(size=50) {
|
||||||
'</defs>';
|
'</defs>';
|
||||||
};
|
};
|
||||||
|
|
||||||
CommandCache.prototype.toSVG = function() {
|
TurtleShepherd.prototype.toSVG = function() {
|
||||||
|
|
||||||
//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";
|
|
@ -1,15 +1,15 @@
|
||||||
|
|
||||||
cmdCache = new CommandCache();
|
turtleShepherd = new TurtleShepherd();
|
||||||
DEBUG = true;
|
DEBUG = true;
|
||||||
|
|
||||||
function reDraw(cnv) {
|
function reDraw(cnv) {
|
||||||
//load a svg snippet in the canvas with id = 'svg'
|
//load a svg snippet in the canvas with id = 'svg'
|
||||||
canvas = document.getElementById('svg');
|
canvas = document.getElementById('svg');
|
||||||
//document.getElementById("code").innerHTML = cmdCache.toSVG();
|
//document.getElementById("code").innerHTML = cmdCache.toSVG();
|
||||||
//document.getElementById("svg2").innerHTML = cmdCache.toSVG();
|
document.getElementById("svg2").innerHTML = turtleShepherd.toSVG();
|
||||||
//canvg(document.getElementById('svg'), cmdCache.toSVG());
|
//canvg(document.getElementById('svg'), cmdCache.toSVG());
|
||||||
|
|
||||||
canvg(cnv, cmdCache.toSVG());
|
//canvg(cnv, cmdCache.toSVG());
|
||||||
|
|
||||||
//var cnv = caller.parent.penTrails();
|
//var cnv = caller.parent.penTrails();
|
||||||
//var ctx = cnv.getContext('2d');
|
//var ctx = cnv.getContext('2d');
|
||||||
|
|
Ładowanie…
Reference in New Issue