From 4455adff4b58f538f990df9131ab18ccbf74db79 Mon Sep 17 00:00:00 2001 From: Michael Aschauer Date: Sun, 11 Nov 2018 14:23:36 +0100 Subject: [PATCH] make font drawing along the heading --- stitchcode/objects.js | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/stitchcode/objects.js b/stitchcode/objects.js index fa0dcebe..8ca3c0f6 100644 --- a/stitchcode/objects.js +++ b/stitchcode/objects.js @@ -923,6 +923,12 @@ SpriteMorph.prototype.drawText = function (text, scale) { } if (stage.fonts) { + heading = this.heading; + vx = Math.cos(radians(this.heading - 90)); + vy = Math.sin(radians(this.heading - 90)); + nx = Math.cos(radians(this.heading )); + ny = Math.sin(radians(this.heading )); + for(var i in text) { var index = text.charCodeAt(i) - 33; var x = this.xPosition(); @@ -930,6 +936,8 @@ SpriteMorph.prototype.drawText = function (text, scale) { var maxx = 0, maxy = 0; var nextIsPenUp = false; + + if (stage.fonts[text[i]]){ if (this.isRunning) coords = stage.fonts[text[i]]["stitch"]; @@ -959,30 +967,40 @@ SpriteMorph.prototype.drawText = function (text, scale) { nextIsPenUp = false; } else { maxx = Math.max(maxx, coords[j][0]); + dx = coords[j][0] * scale * vx - coords[j][1] * scale * vy; + dy = coords[j][1] * scale * ny - coords[j][0] * scale * nx; if (nextIsPenUp || j == 0 ) { doAJump( - x + coords[j][0] * scale, - y - coords[j][1] * scale ) + x + dx, + y - dy + ) } else if (nextIsStitch) { this.gotoXY( - x + coords[j][0] * scale, - y - coords[j][1] * scale) + x + dx, + y - dy + ) } else { var runState = this.isRunning; this.isRunning = false; this.gotoXYBy( - x + coords[j][0] * scale, - y - coords[j][1] * scale, 40 ); + x + dx, + y - dy, + 40 ); this.isRunning = runState; } } } - doAJump(x + (maxx + 5) * scale, y ); + dx = (maxx+5) * scale * vx; + dy = 0 - (maxx+5) * scale * nx; + doAJump(x + dx, y - dy); } else { - doAJump(x + (10 * scale), y ); + dx = 10 * scale * vx; + dy = 0 - 10 * scale * nx; + doAJump(x + dx, y - dy); } } + this.setHeading(heading); } else { console.log("no fonts loaded"); console.log(stage.fonts);