kopia lustrzana https://github.com/backface/turtlestitch
add asteroid font
rodzic
fc7a77052a
commit
724b6ea633
|
@ -0,0 +1,71 @@
|
|||
{
|
||||
"0": [ [0,0], [8,0], [8,12], [0,12], [0,0], [8,12], "FONT_LAST" ],
|
||||
"1": [ [4,0], [4,12], [3,10], "FONT_LAST" ],
|
||||
"2": [ [0,12], [8,12], [8,7], [0,5], [0,0], [8,0], "FONT_LAST" ],
|
||||
"3": [ [0,12], [8,12], [8,0], [0,0], "FONT_UP", [0,6], [8,6], "FONT_LAST" ],
|
||||
"4": [ [0,12], [0,6], [8,6], "FONT_UP", [8,12], [8,0], "FONT_LAST" ],
|
||||
"5": [ [0,0], [8,0], [8,6], [0,7], [0,12], [8,12], "FONT_LAST" ],
|
||||
"6": [ [0,12], [0,0], [8,0], [8,5], [0,7], "FONT_LAST" ],
|
||||
"7": [ [0,12], [8,12], [8,6], [4,0], "FONT_LAST" ],
|
||||
"8": [ [0,0], [8,0], [8,12], [0,12], [0,0], "FONT_UP", [0,6], [8,6], "FONT_LAST" ],
|
||||
"9": [ [8,0], [8,12], [0,12], [0,7], [8,5], "FONT_LAST" ],
|
||||
" ": [ "FONT_LAST", "FONT_LAST" ],
|
||||
".": [ [3,0], [4,0], "FONT_LAST" ],
|
||||
",": [ [2,0], [4,2], "FONT_LAST" ],
|
||||
"-": [ [2,6], [6,6], "FONT_LAST" ],
|
||||
"+": [ [1,6], [7,6], "FONT_UP", [4,9], [4,3], "FONT_LAST" ],
|
||||
"!": [ [4,0], [3,2], [5,2], [4,0], "FONT_UP", [4,4], [4,12], "FONT_LAST" ],
|
||||
"#": [ [0,4], [8,4], [6,2], [6,10], [8,8], [0,8], [2,10], [2,2], "FONT_LAST" ],
|
||||
"^": [ [2,6], [4,12], [6,6], "FONT_LAST" ],
|
||||
"=": [ [1,4], [7,4], "FONT_UP", [1,8], [7,8], "FONT_LAST" ],
|
||||
"*": [ [0,0], [4,12], [8,0], [0,8], [8,8], [0,0], "FONT_LAST" ],
|
||||
"_": [ [0,0], [8,0], "FONT_LAST" ],
|
||||
"/": [ [0,0], [8,12], "FONT_LAST" ],
|
||||
"\\": [ [0,12], [8,0], "FONT_LAST" ],
|
||||
"@": [ [8,4], [4,0], [0,4], [0,8], [4,12], [8,8], [4,4], [3,6], "FONT_LAST" ],
|
||||
"$": [ [6,2], [2,6], [6,10], "FONT_UP", [4,12], [4,0], "FONT_LAST" ],
|
||||
"&": [ [8,0], [4,12], [8,8], [0,4], [4,0], [8,4], "FONT_LAST" ],
|
||||
"[": [ [6,0], [2,0], [2,12], [6,12], "FONT_LAST" ],
|
||||
"]": [ [2,0], [6,0], [6,12], [2,12], "FONT_LAST" ],
|
||||
"(": [ [6,0], [2,4], [2,8], [6,12], "FONT_LAST" ],
|
||||
")": [ [2,0], [6,4], [6,8], [2,12], "FONT_LAST" ],
|
||||
"{": [ [6,0], [4,2], [4,10], [6,12], "FONT_UP", [2,6], [4,6], "FONT_LAST" ],
|
||||
"}": [ [4,0], [6,2], [6,10], [4,12], "FONT_UP", [6,6], [8,6], "FONT_LAST" ],
|
||||
"%": [ [0,0], [8,12], "FONT_UP", [2,10], [2,8], "FONT_UP", [6,4], [6,2], "FONT_LAST" ],
|
||||
"<": [ [6,0], [2,6], [6,12], "FONT_LAST" ],
|
||||
">": [ [2,0], [6,6], [2,12], "FONT_LAST" ],
|
||||
"|": [ [4,0], [4,5], "FONT_UP", [4,6], [4,12], "FONT_LAST" ],
|
||||
":": [ [4,9], [4,7], "FONT_UP", [4,5], [4,3], "FONT_LAST" ],
|
||||
";": [ [4,9], [4,7], "FONT_UP", [4,5], [1,2], "FONT_LAST" ],
|
||||
"\"": [ [2,10], [2,6], "FONT_UP", [6,10], [6,6], "FONT_LAST" ],
|
||||
"'": [ [2,6], [6,10], "FONT_LAST" ],
|
||||
"`": [ [2,10], [6,6], "FONT_LAST" ],
|
||||
"~": [ [0,4], [2,8], [6,4], [8,8], "FONT_LAST" ],
|
||||
"?": [ [0,8], [4,12], [8,8], [4,4], "FONT_UP", [4,1], [4,0], "FONT_LAST" ],
|
||||
"A": [ [0,0], [0,8], [4,12], [8,8], [8,0], "FONT_UP", [0,4], [8,4], "FONT_LAST" ],
|
||||
"B": [ [0,0], [0,12], [4,12], [8,10], [4,6], [8,2], [4,0], [0,0], "FONT_LAST" ],
|
||||
"C": [ [8,0], [0,0], [0,12], [8,12], "FONT_LAST" ],
|
||||
"D": [ [0,0], [0,12], [4,12], [8,8], [8,4], [4,0], [0,0], "FONT_LAST" ],
|
||||
"E": [ [8,0], [0,0], [0,12], [8,12], "FONT_UP", [0,6], [6,6], "FONT_LAST" ],
|
||||
"F": [ [0,0], [0,12], [8,12], "FONT_UP", [0,6], [6,6], "FONT_LAST" ],
|
||||
"G": [ [6,6], [8,4], [8,0], [0,0], [0,12], [8,12], "FONT_LAST" ],
|
||||
"H": [ [0,0], [0,12], "FONT_UP", [0,6], [8,6], "FONT_UP", [8,12], [8,0], "FONT_LAST" ],
|
||||
"I": [ [0,0], [8,0], "FONT_UP", [4,0], [4,12], "FONT_UP", [0,12], [8,12], "FONT_LAST" ],
|
||||
"J": [ [0,4], [4,0], [8,0], [8,12], "FONT_LAST" ],
|
||||
"K": [ [0,0], [0,12], "FONT_UP", [8,12], [0,6], [6,0], "FONT_LAST" ],
|
||||
"L": [ [8,0], [0,0], [0,12], "FONT_LAST" ],
|
||||
"M": [ [0,0], [0,12], [4,8], [8,12], [8,0], "FONT_LAST" ],
|
||||
"N": [ [0,0], [0,12], [8,0], [8,12], "FONT_LAST" ],
|
||||
"O": [ [0,0], [0,12], [8,12], [8,0], [0,0], "FONT_LAST" ],
|
||||
"P": [ [0,0], [0,12], [8,12], [8,6], [0,5], "FONT_LAST" ],
|
||||
"Q": [ [0,0], [0,12], [8,12], [8,4], [0,0], "FONT_UP", [4,4], [8,0], "FONT_LAST" ],
|
||||
"R": [ [0,0], [0,12], [8,12], [8,6], [0,5], "FONT_UP", [4,5], [8,0], "FONT_LAST" ],
|
||||
"S": [ [0,2], [2,0], [8,0], [8,5], [0,7], [0,12], [6,12], [8,10], "FONT_LAST" ],
|
||||
"T": [ [0,12], [8,12], "FONT_UP", [4,12], [4,0], "FONT_LAST" ],
|
||||
"U": [ [0,12], [0,2], [4,0], [8,2], [8,12], "FONT_LAST" ],
|
||||
"V": [ [0,12], [4,0], [8,12], "FONT_LAST" ],
|
||||
"W": [ [0,12], [2,0], [4,4], [6,0], [8,12], "FONT_LAST" ],
|
||||
"X": [ [0,0], [8,12], "FONT_UP", [0,12], [8,0], "FONT_LAST" ],
|
||||
"Y": [ [0,12], [4,6], [8,12], "FONT_UP", [4,6], [4,0], "FONT_LAST" ],
|
||||
"Z": [ [0,12], [8,12], [0,0], [8,0], "FONT_UP", [2,6], [6,6], "FONT_LAST" ]
|
||||
}
|
Plik diff jest za duży
Load Diff
|
@ -337,13 +337,23 @@ SpriteMorph.prototype.drawText = function (text, scale, fontnr) {
|
|||
|
||||
if (!stage) {return; }
|
||||
|
||||
// implement Hershey fonts.
|
||||
// Json data from:
|
||||
|
||||
// a few basic Hershey fonts.
|
||||
// https://en.wikipedia.org/wiki/Hershey_fonts
|
||||
// retrieved from
|
||||
// https://techninja.github.io/hersheytextjs/
|
||||
|
||||
var font = "futuram"
|
||||
if (fontnr == 1) font = "scripts"
|
||||
if (fontnr == 2) font = "futural"
|
||||
|
||||
// Asteroid font
|
||||
// retrieved from https://trmm.net/Asteroids_font
|
||||
if (fontnr == 3) font = "asteroid"
|
||||
|
||||
if (fontnr == 3) {
|
||||
scale = scale * 2;
|
||||
}
|
||||
|
||||
if (stage.fonts) {
|
||||
for(var i in text) {
|
||||
|
@ -351,42 +361,72 @@ SpriteMorph.prototype.drawText = function (text, scale, fontnr) {
|
|||
var x = this.xPosition();
|
||||
var y = this.yPosition();
|
||||
var maxx = 0, maxy = 0;
|
||||
if (stage.fonts[font].chars[index]){
|
||||
commands = stage.fonts[font].chars[index].d.split(' ');
|
||||
for (var i =0; i<commands.length; i++) {
|
||||
var coord = commands[i].split(',');
|
||||
if (coord[0][0] == "M") {
|
||||
coord[0] = coord[0].replace('M','')
|
||||
} else if (coord[0][0] == "L") {
|
||||
coord[0] = coord[0].replace('L','');
|
||||
}
|
||||
maxx = Math.max(maxx, parseInt(coord[0]))
|
||||
maxy = Math.max(maxy, parseInt(coord[1]))
|
||||
}
|
||||
for (var i =0; i<commands.length; i++) {
|
||||
var coord = commands[i].split(',');
|
||||
if (coord[0][0] == "M") {
|
||||
coord[0] = coord[0].replace('M','')
|
||||
var penState = this.isDown;
|
||||
this.isDown = false;
|
||||
this.gotoXY(x + parseInt(coord[0]) * scale, y + (maxy - parseInt(coord[1])) * scale,)
|
||||
this.isDown = penState;
|
||||
} else if (coord[0][0] == "L") {
|
||||
coord[0] = coord[0].replace('L','');
|
||||
this.gotoXYBy(x + parseInt(coord[0]) * scale, y + (maxy - parseInt(coord[1])) * scale, 10 )
|
||||
} else {
|
||||
this.gotoXYBy(x + parseInt(coord[0]) * scale, y + (maxy - parseInt(coord[1])) * scale, 10 )
|
||||
var nextPenIsUp = false;
|
||||
if (fontnr == 3) {
|
||||
if (stage.afonts[text[i].toUpperCase()]){
|
||||
coords = stage.afonts[text[i].toUpperCase()];
|
||||
for (var j =0; j<coords.length; j++) {
|
||||
if (coords[j] == "FONT_UP") {
|
||||
nextPenIsUp = true;
|
||||
} else if (coords[j] == "FONT_LAST") {
|
||||
// ignore last
|
||||
} else {
|
||||
if (nextPenIsUp) {
|
||||
var penState = this.isDown;
|
||||
this.isDown = false;
|
||||
this.gotoXY(x + coords[j][0] * scale, y + coords[j][1] * scale )
|
||||
this.isDown = penState;
|
||||
nextPenIsUp = false;
|
||||
} else {
|
||||
this.gotoXYBy(x + coords[j][0] * scale, y + coords[j][1] * scale, 10 )
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var penState = this.isDown;
|
||||
this.isDown = false;
|
||||
this.gotoXY(x + (stage.fonts[font].chars[index].o * 1.7) * scale, y)
|
||||
this.isDown = penState;
|
||||
} else {
|
||||
var penState = this.isDown
|
||||
this.isDown = false;
|
||||
this.gotoXY(x + 10 * scale, y)
|
||||
this.isDown = penState;
|
||||
if (i < text.length) {
|
||||
var penState = this.isDown;
|
||||
this.isDown = false;
|
||||
this.gotoXY(x + (10 * scale), y );
|
||||
this.isDown = penState;
|
||||
}
|
||||
} else {
|
||||
if (stage.fonts[font].chars[index]){
|
||||
commands = stage.fonts[font].chars[index].d.split(' ');
|
||||
for (var i =0; i<commands.length; i++) {
|
||||
var coord = commands[i].split(',');
|
||||
if (coord[0][0] == "M") {
|
||||
coord[0] = coord[0].replace('M','')
|
||||
} else if (coord[0][0] == "L") {
|
||||
coord[0] = coord[0].replace('L','');
|
||||
}
|
||||
maxx = Math.max(maxx, parseInt(coord[0]))
|
||||
maxy = Math.max(maxy, parseInt(coord[1]))
|
||||
}
|
||||
for (var i =0; i<commands.length; i++) {
|
||||
var coord = commands[i].split(',');
|
||||
if (coord[0][0] == "M") {
|
||||
coord[0] = coord[0].replace('M','')
|
||||
var penState = this.isDown;
|
||||
this.isDown = false;
|
||||
this.gotoXY(x + parseInt(coord[0]) * scale, y + (maxy - parseInt(coord[1])) * scale,)
|
||||
this.isDown = penState;
|
||||
} else if (coord[0][0] == "L") {
|
||||
coord[0] = coord[0].replace('L','');
|
||||
this.gotoXYBy(x + parseInt(coord[0]) * scale, y + (maxy - parseInt(coord[1])) * scale, 10 )
|
||||
} else {
|
||||
this.gotoXYBy(x + parseInt(coord[0]) * scale, y + (maxy - parseInt(coord[1])) * scale, 10 )
|
||||
}
|
||||
}
|
||||
var penState = this.isDown;
|
||||
this.isDown = false;
|
||||
this.gotoXY(x + (stage.fonts[font].chars[index].o * 1.7) * scale, y)
|
||||
this.isDown = penState;
|
||||
} else {
|
||||
var penState = this.isDown
|
||||
this.isDown = false;
|
||||
this.gotoXY(x + 10 * scale, y)
|
||||
this.isDown = penState;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -522,7 +562,7 @@ StageMorph.prototype.init = function (globals) {
|
|||
function loadFont(callback) {
|
||||
var xobj = new XMLHttpRequest();
|
||||
xobj.overrideMimeType("application/json");
|
||||
xobj.open('GET', 'stitchcode/hershey/fonts.json', true);
|
||||
xobj.open('GET', 'stitchcode/fonts/hershey.json', true);
|
||||
xobj.onreadystatechange = function () {
|
||||
if (xobj.readyState == 4 && xobj.status == "200") {
|
||||
callback(xobj.responseText);
|
||||
|
@ -537,6 +577,27 @@ StageMorph.prototype.init = function (globals) {
|
|||
});
|
||||
}
|
||||
|
||||
// load Asteroid font
|
||||
// retrieved from https://trmm.net/Asteroids_font
|
||||
|
||||
function loadAsteroidFont(callback) {
|
||||
var xobj = new XMLHttpRequest();
|
||||
xobj.overrideMimeType("application/json");
|
||||
xobj.open('GET', 'stitchcode/fonts/asteroid.json', true);
|
||||
xobj.onreadystatechange = function () {
|
||||
if (xobj.readyState == 4 && xobj.status == "200") {
|
||||
callback(xobj.responseText);
|
||||
}
|
||||
};
|
||||
xobj.send(null);
|
||||
}
|
||||
|
||||
if (!this.afonts) {
|
||||
loadAsteroidFont(function(response) {
|
||||
myself.afonts = JSON.parse(response);
|
||||
});
|
||||
}
|
||||
|
||||
this.turtleShepherd = new TurtleShepherd();
|
||||
|
||||
this.scene.grid.draw();
|
||||
|
|
Ładowanie…
Reference in New Issue