Skip to content

Commit

Permalink
proof of concept
Browse files Browse the repository at this point in the history
  • Loading branch information
katsaii committed Feb 22, 2024
1 parent a6ff8c5 commit ed2674d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
10 changes: 10 additions & 0 deletions bit-font.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<meta charset="utf-8">
<script src="./sob/sob-html.js"></script>
<script src="./bit-font.js"></script>
<a href="./index.html">&lt;&lt; back</a>
<p>upload a json file exported from <a href="https://www.pentacom.jp/pentacom/bitfontmaker2/">Bit Font Maker 2</a> (using the <img style="vertical-align : middle" src="https://www.pentacom.jp/pentacom/bitfontmaker2/img/menu_data.gif"> "<code>Data Import/Export</code>" button)</p>
<input type="file" id="json-file">
<hr>
<button onclick="bitFontIntoImage()">Bit Font Maker json -&gt; image</button>
<hr>
<div id="dest"></div>
25 changes: 25 additions & 0 deletions bit-font.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//a.files[0].arrayBuffer().then(x => {
// let tc = new TextDecoder("utf-8");
// console.log(tc.decode(x));
//})
const getFileBuffer = () => document.getElementById("json-file").files[0];
const isNumeric = (n) => !isNaN(n);
const dec2bin = (dec) => (dec >>> 0).toString(2);

const bitFontIntoImage = () => getFileBuffer().text().then((text) => {
const json = JSON.parse(text);
for (const charCode in json) {
if (!isNumeric(charCode)) {
continue;
}
const char = String.fromCharCode(charCode);
console.log(`"${charCode}" ${char}`);
const frameData = json[charCode];
let debugView = "";
for (const line of frameData) {
const bits = dec2bin(line);
debugView += bits.padStart(16, "0").split("").reverse().join("") + "\n";
}
console.log(debugView.replaceAll("0", " ").replaceAll("1", "■"));
}
});
10 changes: 5 additions & 5 deletions morse-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const getCharSets = () => {
return charSets;
}

function writeMorseCodeData(sb, morse, decoder) {
const writeMorseCodeData = (sb, morse, decoder) => {
var morseBin = sobMorseImplode(morse);
sb.writeVoidTag("br");
sb.writeResultRichText("morse code binary signal", morseBin);
Expand All @@ -63,7 +63,7 @@ function writeMorseCodeData(sb, morse, decoder) {
});
}

function writeMorseCodeAudio(sb, morse) {
const writeMorseCodeAudio = (sb, morse) => {
const morseBin = sobMorseImplode(morse);
const audioCtx = new (window.AudioContext || window.webkitAudioContext)();
const ditLength = 0.1;
Expand All @@ -88,7 +88,7 @@ function writeMorseCodeAudio(sb, morse) {
sb.writeAudio(url, "audio/wav");
}

function encodeMorse() {
const encodeMorse = () => {
const text = getTextContent();
const charSets = getCharSets();
const encoder = sobMorseEncoderCreate(...charSets);
Expand All @@ -103,7 +103,7 @@ function encodeMorse() {
setResultHTML(sb);
}

function decodeMorse() {
const decodeMorse = () => {
const morseDitDah = getTextContent();
const decoder = sobMorseDecoderCreate(...getCharSets());
const morse = sobMorseExplodeDitDah(morseDitDah);
Expand All @@ -116,7 +116,7 @@ function decodeMorse() {
setResultHTML(sb);
}

function decodeMorseBinary() {
const decodeMorseBinary = () => {
const morseBin = getTextContent();
const decoder = sobMorseDecoderCreate(...getCharSets());
const morse = sobMorseExplode(morseBin);
Expand Down
4 changes: 2 additions & 2 deletions word-count.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const getTextContent = () => document.getElementById("src").value;
const setResultHTML = (html) => document.getElementById("dest").innerHTML = html;

function getCounts() {
const getCounts = () => {
const text = getTextContent();
const words = sobStringToWords(text);
const chars = sobStringToChars(text);
Expand Down Expand Up @@ -37,7 +37,7 @@ function getCounts() {
console.log("got counts");
}

function getStats() {
const getStats = () => {
const text = getTextContent();
const wordFreq = sobStatFrequencies(sobStringToWords(text));
const charFreq = sobStatFrequencies(sobStringToChars(text));
Expand Down

0 comments on commit ed2674d

Please sign in to comment.