Skip to content

Commit

Permalink
switch to OctoGlyphs, why not
Browse files Browse the repository at this point in the history
  • Loading branch information
paulfitz committed Oct 16, 2019
1 parent 0bfde89 commit 499b606
Show file tree
Hide file tree
Showing 17 changed files with 593 additions and 100 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ help:
./make.sh help

dock:
cd docker && docker build -t paulfitz/cosmicos_builder .
cd docker && cp ../package.json . && docker build -t paulfitz/cosmicos_builder .

%:
./make.sh $*
3 changes: 2 additions & 1 deletion make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ fi

# start a container in the background, just to make builds more responsive
docker ps -f name=cosmicos_build | grep -q cosmicos || {
docker run -dit --rm $args --name cosmicos_build -v $PWD:/cosmicos paulfitz/cosmicos_builder /bin/bash
docker run --rm --name cosmicos_build -v $PWD:/cosmicos paulfitz/cosmicos_builder src/prepare_node.sh
docker run -dit --rm $args --name cosmicos_build -v $PWD:/cosmicos -v $PWD/node_modules_docker:/cosmicos/node_modules paulfitz/cosmicos_builder /bin/bash
}

# run our actual build command, finally
Expand Down
13 changes: 7 additions & 6 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ add_custom_command(OUTPUT ${WORK}/CosmicEval.js
add_custom_command(OUTPUT ${WORK}/SpiderScrawl.js
COMMAND ${HAXE} -js SpiderScrawl.js -main cosmicos.SpiderScrawl -cp ${SRC}
WORKING_DIRECTORY ${WORK}
DEPENDS ${SRC}/cosmicos/SpiderScrawl.hx)
DEPENDS ${SRC}/cosmicos/SpiderScrawl.hx ${SRC}/cosmicos/GlyphCode.hx)

add_custom_command(OUTPUT ${WORK}/OghamStyle.js
COMMAND ${HAXE} -js OghamStyle.js -main cosmicos.OghamStyle -cp ${SRC}
Expand All @@ -70,8 +70,7 @@ add_custom_target(jshelpers ALL DEPENDS
${WORK}/CosmicAudio.js
${WORK}/CosmicEval.js
${WORK}/SpiderScrawl.js
${WORK}/OghamStyle.js
)
${WORK}/OghamStyle.js)



Expand Down Expand Up @@ -114,6 +113,7 @@ FILE(WRITE ${WORK}/setup.cmake "
set(ENCODER \"${FritzifierLoc}\")
set(BCEL \"${BCEL_JAR}\")
set(NODE \"${NODE}\")
set(TSNODE \"${CMAKE_SOURCE_DIR}/node_modules/.bin/ts-node\")
")

set(ACTIVE_DEPENDS)
Expand Down Expand Up @@ -248,15 +248,16 @@ file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/assets/icons/spider)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/assets/fonts/spider)
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/assets/fonts/spider/cosmic_spider.ttf
COMMAND ${CMAKE_COMMAND}
"-Din:STRING=${CMAKE_SOURCE_DIR}/src/font/generate_glyphs.js"
"-Din:STRING=${CMAKE_SOURCE_DIR}/src/font/generate_glyphs.ts"
"-Dnargs:STRING=${CMAKE_BINARY_DIR}/assets"
"-Dlog:STRING=spider"
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/node.cmake
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/typescript.cmake
WORKING_DIRECTORY ${WORK}
DEPENDS
${WORK}/SpiderScrawl.js
${CMAKE_SOURCE_DIR}/src/font/glyphs_to_svg.sh
${CMAKE_SOURCE_DIR}/src/font/generate_glyphs.js)
${CMAKE_SOURCE_DIR}/src/font/OctoGlyph.ts
${CMAKE_SOURCE_DIR}/src/font/generate_glyphs.ts)

add_custom_target(spider DEPENDS ${CMAKE_BINARY_DIR}/assets/fonts/spider/cosmic_spider.ttf)

Expand Down
2 changes: 1 addition & 1 deletion src/assemble/CosmicDrive.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var CosmicDrive = function(options) {
var fs = require('fs');
this.cosmicos = require("CosmicEval").cosmicos;
this.spiders = require("SpiderScrawl").cosmicos;
this.spider = new this.spiders.SpiderScrawl(null,0,0);
this.spider = new this.spiders.GlyphCode('octo');

this.all = JSON.parse(fs.readFileSync("assem.json", 'utf8'));
this.config = new this.cosmicos.Config(fs.readFileSync("config.json", 'utf8'));
Expand Down
38 changes: 35 additions & 3 deletions src/assemble/cosmicos.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ var stop_phrase = "";
var wrap = false;
var comments = true;

const vowels = ['a', 'i', 'o', 'e'];
const consonants = ['t', 's', 'p', 'k', 'd', 'z', 'b', 'g'];

function needStanza() {
if (stanza==-1) {
throw "Please specify a message part with -p NNNN";
Expand Down Expand Up @@ -54,8 +57,9 @@ function expand(e, letters, acks) {
}

function showSpider(root,src) {
var cos = require(root + "/src/SpiderScrawl").cosmicos;
var ss = new cos.SpiderScrawl(null,0,0);
var cos = require(root + "/src/SpiderScrawl").cosmicos;
var mode = 'octo';
var ss = new cos.GlyphCode(mode);
var path = root + "/assets/fonts/spider/";
if (wrap) {
process.stdout.write("<!DOCTYPE html>\
Expand Down Expand Up @@ -91,17 +95,45 @@ function showSpider(root,src) {
word-break: break-all; \
background: white; \
color: blue; \
width: 100vw; \
} \
p { \
margin: 0; \
padding: 0; \
padding: 5px; \
display: block; \
} \
p, .scrawl { \
overflow-wrap: break-word; \
word-wrap: break-word; \
word-break: break-word; \
letter-spacing: 2px; \
} \
</style>\
</head>\
<body>\
");
}
if (mode === 'octo') {
const mappings = [];
for (let i=0; i<64; i++) {
ss.reset();
const txt = ss.addString("2" + i.toString(2) + "3");
const vowel = vowels[i & 0x3];
const consonant = consonants[(i & 0x38) >> 3];
const nasal = (i & 0x4) ? 'n' : '';
const latin = consonant + vowel + nasal;
mappings.push({i, txt, latin});
}
mappings.push({i: '(1)', txt: ss.addString('22133'), latin: 'du ti bu'});
mappings.push({i: '(1|0)', txt: ss.addString('22131232033'), latin: 'du ti gu ta bu'});
mappings.push({i: '($1)', txt: ss.addString('20232133'), latin: 'du suti bu'});
mappings.push({i: '1~', txt: ss.addString('2132233'), latin: 'ti zun'});
process.stdout.write("<table>\n");
for (const {i, latin, txt} of mappings) {
process.stdout.write(`<tr><td>${i}</td><td>${latin}</td><td class=scrawl>${txt}</td></tr>\n`);
}
process.stdout.write("</table>\n");
}
for (var s=stanza; s<=last_stanza; s++) {
var m = msg[s];
if (!m) continue;
Expand Down
3 changes: 3 additions & 0 deletions src/cmake/typescript.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include(setup.cmake)
set(ENV{NODE_PATH} "${out_dir}:${path}:$ENV{NODE_PATH}")
execute_process(COMMAND ${TSNODE} ${in} ${nargs} OUTPUT_FILE ${out_dir}/${log}.txt)
173 changes: 173 additions & 0 deletions src/cosmicos/GlyphCode.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
// -*- mode:java; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-

package cosmicos;

@:expose
class GlyphCode {
private var top : Int;
private var base : Int;
private var bits : Int;
private var mode : Bool;
private var paren : Int;
private var q : String;
private var last4 : String;
private var useSpace : Bool;
private var needSpace : Bool;

public function new(flavor: String) {
if (flavor == "octo") {
base = 0xf144;
bits = 6;
useSpace = true;
} else {
base = 0xf100;
bits = 4;
useSpace = false;
}
top = Std.int(Math.pow(2, bits));
reset();
}

public function reset() {
mode = false;
paren = 0;
q = "";
last4 = "";
needSpace = false;
}

public function addString(txt: String) {
var s = "";
if (useSpace) {
// sneaking in special rendering of | and $.
txt = StringTools.replace(txt, "123", "243");
txt = StringTools.replace(txt, "023", "253");
txt = StringTools.replace(txt, "2233", "273");
}
for (i in 0...txt.length) {
var ch = txt.substr(i,1);
if (ch<"0"||ch>"7") {
if (ch=="\n") {
s += "<br />\n";
}
continue;
}
s += addChar(ch);
if (last4.length>=4) {
last4 = last4.substr(1,3) + ch;
} else {
last4 = last4 + ch;
}
if (last4 == "2233") {
incLine();
}
}
return s;
}

public function incLine() {
}

public function incPos() {
}

public function showChar1(hasNum: Bool, n: Int, open: Bool, close: Bool) : String {
var idx : Int = 0;
if (hasNum) {
idx = (open?1:0);
idx *= 2;
idx += (close?1:0);
idx *= top;
idx += n;
} else {
idx += 2 * 2 * top;
idx += n;
if (n==0) {
idx += open ? 2 : 0;
idx += close ? 1 : 0;
}
}
idx += base;
return "&#x" + StringTools.hex(idx) + ";";
}

public function showChar(hasNum: Bool, n: Int, open: Bool, close: Bool) : String {
var space: String = "";
if (useSpace) {
if (hasNum) {
if (needSpace) {
space = showChar1(false, 6, false, false);
needSpace = false;
}
if (close) {
needSpace = true;
}
open = false;
close = false;
} else {
needSpace = false;
}
}
incPos();
return space + showChar1(hasNum, n, open, close);
}

public function addChar(ch: String) {
var txt : String = "";
if (ch == "2") {
if (mode) {
txt += showChar(false,0,true,false);
} else {
mode = true;
}
paren++;
} else if (ch == "3") {
paren--;
if (mode) {
if (q.length>100) {
txt += showChar(false,0,true,false);
for (i in 0...q.length) {
txt += showChar(true,Std.parseInt(q.substr(i,1)),false,false);
}
txt += showChar(false,0,false,true);
} else if (q.length>0) {
if (q == "4" || q == "5" || q == "7") {
// sneaking in special rendering of | and $ and EOL.
txt += showChar(false, Std.parseInt(q), false, false);
} else {
var len = q.length;
while (len%bits!=0) {
q = "0" + q;
len = q.length;
}
var blen = Std.int((len-1)/bits+1);
for (i in 0...blen) {
var part : String = q.substr(i*bits,bits);
var v = 0;
for (j in 0...bits) {
v *= 2;
if (part.charAt(j)=='1') {
v++;
}
}
txt += showChar(true,v,(i==0),(i==blen-1));
}
}
} else {
txt += showChar(false,0,true,true);
}
q = "";
mode = false;
} else {
txt += showChar(false,0,false,true);
}
} else {
if (mode) {
q += ch;
} else {
txt += showChar(true,Std.parseInt(ch),false,false);
}
}
return txt;
}
}
29 changes: 27 additions & 2 deletions src/cosmicos/SpiderScrawl.hx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,17 @@ class SpiderScrawl {
private var q : String;
private var last4 : String;

public function new(im : SpiderImage, ww: Int, hh: Int,
public function new(im : SpiderImage = null, ww: Int = 32, hh: Int = 32,
w: Int = 32, h: Int = 32) {
if (im != null || ww != 32) {
this.attach(im, ww, hh, w, h);
}
}

public function attach(im : SpiderImage, ww: Int, hh: Int,
w: Int = 0, h: Int = 0) {
if (w == 0) { w = ww; }
if (h == 0) { h = hh; }
this.im = im;
this.ww = ww;
this.hh = hh;
Expand All @@ -36,6 +45,10 @@ class SpiderScrawl {
last4 = "";
}

public function getGlyphCode() {
return new GlyphCode("spider");
}

public function line(x0: Float, y0: Float, x1: Float, y1: Float, color: Array<Int>) {
// ignore color, that is from old code
if (im!=null) {
Expand Down Expand Up @@ -189,6 +202,18 @@ class SpiderScrawl {
return "&#x" + StringTools.hex(idx) + ";";
}

public function count() {
return 16;
}

public function defaultWidth() {
return 32;
}

public function defaultHeight() {
return 32;
}

public function addChar(ch: String) {
var txt : String = "";
if (ch == "2") {
Expand Down Expand Up @@ -243,7 +268,7 @@ class SpiderScrawl {
return txt;
}

private function addString(txt: String) {
public function addString_DEPRECATED(txt: String) {
var s = "";
for (i in 0...txt.length) {
var ch = txt.substr(i,1);
Expand Down
Loading

0 comments on commit 499b606

Please sign in to comment.