dev-2.0-svg
Michael Aschauer 2017-01-20 10:32:01 +01:00
rodzic b262cf2fa0
commit aac55218f5
4 zmienionych plików z 27 dodań i 28 usunięć

Wyświetl plik

@ -60,9 +60,8 @@
<div id="svg2" style="background:white;font-size:60%;position:absolute;
width:480px;height:360px;left:34%;bottom:0;
border:1px solid #c0c0c0;
display:none" ></div>
position:absolute;right:0;bottom:0;width:480px;height:360px;
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;

Wyświetl plik

@ -6,9 +6,9 @@ SpriteMorph.prototype.forward = function (steps) {
oldx = this.xPosition();
oldy = this.yPosition();
this.origForward(steps);
if (!cmdCache.hasSteps())
cmdCache.initPosition(oldx, oldy);
cmdCache.addMoveTo(this.xPosition() , this.yPosition() , this.isDown);
if (!turtleShepherd.hasSteps())
turtleShepherd.initPosition(oldx, oldy);
turtleShepherd.addMoveTo(this.xPosition() , this.yPosition() , this.isDown);
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 ) {
console.log("jump in place - don't add.");
} else {
if (!cmdCache.hasSteps())
cmdCache.initPosition(oldx, oldy);
cmdCache.addMoveTo(this.xPosition() , this.yPosition() , this.isDown);
if (!turtleShepherd.hasSteps())
turtleShepherd.initPosition(oldx, oldy);
turtleShepherd.addMoveTo(this.xPosition() , this.yPosition() , this.isDown);
this.reDrawTrails();
}
};
@ -31,7 +31,7 @@ SpriteMorph.prototype.gotoXY = function (x, y, justMe) {
SpriteMorph.prototype.origClear = SpriteMorph.prototype.clear;
SpriteMorph.prototype.clear = function () {
this.origClear();
cmdCache.clear();
turtleShepherd.clear();
this.reDrawTrails();
};
@ -46,11 +46,11 @@ SpriteMorph.prototype.reDrawTrails = function () {
StageMorph.prototype.referencePos = null;
StageMorph.prototype.mouseScroll = function (y, x) {
if (y > 0) {
cmdCache.zoomOut();
turtleShepherd.zoomOut();
} else if (y < 0) {
cmdCache.zoomIn();
turtleShepherd.zoomIn();
}
this.clearPenTrails();
reDraw(this.penTrails());
};

Wyświetl plik

@ -1,9 +1,9 @@
function CommandCache() {
function TurtleShepherd() {
this.clear();
}
CommandCache.prototype.addMoveTo= function(x,y,penState) {
TurtleShepherd.prototype.addMoveTo= function(x,y,penState) {
this.cache.push(
{
"cmd":"move",
@ -28,11 +28,11 @@ CommandCache.prototype.addMoveTo= function(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;
};
CommandCache.prototype.addColorChange= function(color) {
TurtleShepherd.prototype.addColorChange= function(color) {
this.cache.push(
{
"cmd":"color",
@ -41,7 +41,7 @@ CommandCache.prototype.addColorChange= function(color) {
);
};
CommandCache.prototype.clear = function() {
TurtleShepherd.prototype.clear = function() {
this.cache = [];
this.minX = 0;
this.minY = 0;
@ -55,35 +55,35 @@ CommandCache.prototype.clear = function() {
this.scale = 1;
};
CommandCache.prototype.initPosition = function(x,y) {
TurtleShepherd.prototype.initPosition = function(x,y) {
this.initX = x;
this.initY = y;
};
CommandCache.prototype.setScale = function(s) {
TurtleShepherd.prototype.setScale = function(s) {
this.scale = s;
if (DEBUG) tstools.debug_msg("zoom to scale "+ s );
};
CommandCache.prototype.zoomIn = function() {
TurtleShepherd.prototype.zoomIn = function() {
this.scale += 0.1;
if (DEBUG) tstools.debug_msg("zoom to scale "+this.scale );
};
CommandCache.prototype.zoomOut = function() {
TurtleShepherd.prototype.zoomOut = function() {
if (this.scale > 0.15)
this.scale -= 0.1;
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.h = y;
};
CommandCache.prototype.renderGrid = function(size=50) {
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"/>' +
@ -91,7 +91,7 @@ CommandCache.prototype.renderGrid = function(size=50) {
'</defs>';
};
CommandCache.prototype.toSVG = function() {
TurtleShepherd.prototype.toSVG = function() {
//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";

Wyświetl plik

@ -1,15 +1,15 @@
cmdCache = new CommandCache();
turtleShepherd = new TurtleShepherd();
DEBUG = true;
function reDraw(cnv) {
//load a svg snippet in the canvas with id = 'svg'
canvas = document.getElementById('svg');
//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(cnv, cmdCache.toSVG());
//canvg(cnv, cmdCache.toSVG());
//var cnv = caller.parent.penTrails();
//var ctx = cnv.getContext('2d');