Skip to content

Instantly share code, notes, and snippets.

@Danny-Engelman
Last active October 24, 2019 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Danny-Engelman/b8f77703545172aac738da1b1b4e25c2 to your computer and use it in GitHub Desktop.
Save Danny-Engelman/b8f77703545172aac738da1b1b4e25c2 to your computer and use it in GitHub Desktop.
Character on 8x8 (LED) Display
display(letter) {
let char2bitarray = (char) => {
const font8x8 = [
[0, 0, 0, 0, 0, 0, 0, 0], // U+0020 (space)
[24, 60, 60, 24, 24, 0, 24, 0], // U+0021 (!)
[54, 54, 0, 0, 0, 0, 0, 0], // U+0022 (")
[54, 54, 127, 54, 127, 54, 54, 0], // U+0023 (#)
[12, 62, 3, 30, 48, 31, 12, 0], // U+0024 ($)
[0, 99, 51, 24, 12, 102, 99, 0], // U+0025 (%)
[28, 54, 28, 110, 59, 51, 110, 0], // U+0026 (&)
[6, 6, 3, 0, 0, 0, 0, 0], // U+0027 (')
[24, 12, 6, 6, 6, 12, 24, 0], // U+0028 (()
[6, 12, 24, 24, 24, 12, 6, 0], // U+0029 ())
[0, 102, 60, 255, 60, 102, 0, 0], // U+002A (*)
[0, 12, 12, 63, 12, 12, 0, 0], // U+002B (+)
[0, 0, 0, 0, 0, 12, 12, 6], // U+002C (,)
[0, 0, 0, 63, 0, 0, 0, 0], // U+002D (-)
[0, 0, 0, 0, 0, 12, 12, 0], // U+002E (.)
[96, 48, 24, 12, 6, 3, 1, 0], // U+002F (/)
[62, 99, 115, 123, 111, 103, 62, 0], // U+0030 (0)
[12, 14, 12, 12, 12, 12, 63, 0], // U+0031 (1)
[30, 51, 48, 28, 6, 51, 63, 0], // U+0032 (2)
[30, 51, 48, 28, 48, 51, 30, 0], // U+0033 (3)
[56, 60, 54, 51, 127, 48, 120, 0], // U+0034 (4)
[63, 3, 31, 48, 48, 51, 30, 0], // U+0035 (5)
[28, 6, 3, 31, 51, 51, 30, 0], // U+0036 (6)
[63, 51, 48, 24, 12, 12, 12, 0], // U+0037 (7)
[30, 51, 51, 30, 51, 51, 30, 0], // U+0038 (8)
[30, 51, 51, 62, 48, 24, 14, 0], // U+0039 (9)
[0, 12, 12, 0, 0, 12, 12, 0], // U+003A (:)
[0, 12, 12, 0, 0, 12, 12, 6], // U+003B (//)
[24, 12, 6, 3, 6, 12, 24, 0], // U+003C (<)
[0, 0, 63, 0, 0, 63, 0, 0], // U+003D (=)
[6, 12, 24, 48, 24, 12, 6, 0], // U+003E (>)
[30, 51, 48, 24, 12, 0, 12, 0], // U+003F (?)
[62, 99, 123, 123, 123, 3, 30, 0], // U+0040 (@)
[12, 30, 51, 51, 63, 51, 51, 0], // U+0041 (A)
[63, 102, 102, 62, 102, 102, 63, 0], // U+0042 (B)
[60, 102, 3, 3, 3, 102, 60, 0], // U+0043 (C)
[31, 54, 102, 102, 102, 54, 31, 0], // U+0044 (D)
[127, 70, 22, 30, 22, 70, 127, 0], // U+0045 (E)
[127, 70, 22, 30, 22, 6, 15, 0], // U+0046 (F)
[60, 102, 3, 3, 115, 102, 124, 0], // U+0047 (G)
[51, 51, 51, 63, 51, 51, 51, 0], // U+0048 (H)
[30, 12, 12, 12, 12, 12, 30, 0], // U+0049 (I)
[120, 48, 48, 48, 51, 51, 30, 0], // U+004A (J)
[103, 102, 54, 30, 54, 102, 103, 0], // U+004B (K)
[15, 6, 6, 6, 70, 102, 127, 0], // U+004C (L)
[99, 119, 127, 127, 107, 99, 99, 0], // U+004D (M)
[99, 103, 111, 123, 115, 99, 99, 0], // U+004E (N)
[28, 54, 99, 99, 99, 54, 28, 0], // U+004F (O)
[63, 102, 102, 62, 6, 6, 15, 0], // U+0050 (P)
[30, 51, 51, 51, 59, 30, 56, 0], // U+0051 (Q)
[63, 102, 102, 62, 54, 102, 103, 0], // U+0052 (R)
[30, 51, 7, 14, 56, 51, 30, 0], // U+0053 (S)
[63, 45, 12, 12, 12, 12, 30, 0], // U+0054 (T)
[51, 51, 51, 51, 51, 51, 63, 0], // U+0055 (U)
[51, 51, 51, 51, 51, 30, 12, 0], // U+0056 (V)
[99, 99, 99, 107, 127, 119, 99, 0], // U+0057 (W)
[99, 99, 54, 28, 28, 54, 99, 0], // U+0058 (X)
[51, 51, 51, 30, 12, 12, 30, 0], // U+0059 (Y)
[127, 99, 49, 24, 76, 102, 127, 0], // U+005A (Z)
[30, 6, 6, 6, 6, 6, 30, 0], // U+005B ([)
[3, 6, 12, 24, 48, 96, 64, 0], // U+005C (\)
[30, 24, 24, 24, 24, 24, 30, 0], // U+005D (])
[8, 28, 54, 99, 0, 0, 0, 0], // U+005E (^)
[0, 0, 0, 0, 0, 0, 0, 255], // U+005F (_)
[12, 12, 24, 0, 0, 0, 0, 0], // U+0060 (`)
[0, 0, 30, 48, 62, 51, 110, 0], // U+0061 (a)
[7, 6, 6, 62, 102, 102, 59, 0], // U+0062 (b)
[0, 0, 30, 51, 3, 51, 30, 0], // U+0063 (c)
[56, 48, 48, 62, 51, 51, 110, 0], // U+0064 (d)
[0, 0, 30, 51, 63, 3, 30, 0], // U+0065 (e)
[28, 54, 6, 15, 6, 6, 15, 0], // U+0066 (f)
[0, 0, 110, 51, 51, 62, 48, 31], // U+0067 (g)
[7, 6, 54, 110, 102, 102, 103, 0], // U+0068 (h)
[12, 0, 14, 12, 12, 12, 30, 0], // U+0069 (i)
[48, 0, 48, 48, 48, 51, 51, 30], // U+006A (j)
[7, 6, 102, 54, 30, 54, 103, 0], // U+006B (k)
[14, 12, 12, 12, 12, 12, 30, 0], // U+006C (l)
[0, 0, 51, 127, 127, 107, 99, 0], // U+006D (m)
[0, 0, 31, 51, 51, 51, 51, 0], // U+006E (n)
[0, 0, 30, 51, 51, 51, 30, 0], // U+006F (o)
[0, 0, 59, 102, 102, 62, 6, 15], // U+0070 (p)
[0, 0, 110, 51, 51, 62, 48, 120], // U+0071 (q)
[0, 0, 59, 110, 102, 6, 15, 0], // U+0072 (r)
[0, 0, 62, 3, 30, 48, 31, 0], // U+0073 (s)
[8, 12, 62, 12, 12, 44, 24, 0], // U+0074 (t)
[0, 0, 51, 51, 51, 51, 110, 0], // U+0075 (u)
[0, 0, 51, 51, 51, 30, 12, 0], // U+0076 (v)
[0, 0, 99, 107, 127, 127, 54, 0], // U+0077 (w)
[0, 0, 99, 54, 28, 54, 99, 0], // U+0078 (x)
[0, 0, 51, 51, 51, 62, 48, 31], // U+0079 (y)
[0, 0, 63, 25, 12, 38, 63, 0], // U+007A (z)
[56, 12, 12, 7, 12, 12, 56, 0], // U+007B ([)
[24, 24, 24, 0, 24, 24, 24, 0], // U+007C (|)
[7, 12, 12, 56, 12, 12, 7, 0], // U+007D (])
[110, 59, 0, 0, 0, 0, 0, 0], // U+007E (~)
];
let idx = char.charCodeAt(0) - 32;
if (idx < 0 || idx > 94) idx = 0;
return font8x8[idx].map((rowbyte, idx) => {
let bits = parseInt(rowbyte, 10).toString(2).padStart(8, "0").split("").reverse();
return bits.map((bit, bitidx) => bit > 0 ? (idx * squarecount + bitidx) : 0);
}).flat();
}
let squarenrs = char2bitarray(letter)
//.filter(x => x)
.map(x => x ? all_board_squares[x] : 0);
console.log(letter, squarenrs);
this.clear_board();
squarenrs.map(square => {
if (square) {
this.add_board_piece('black-pawn', square);
}
});
}
let colorRequests=()=>
[...document.querySelectorAll('.remoteaddress-column')].map(td=>{
let color='pink';
let ip=td.textContent.split`:`[0];
if(ip.includes('52.212.193')) color='lightgreen';
if(ip.includes('::')) color='lightgreen';
if(ip.includes('54.192.33.101')) color='dodgerblue';
if(ip.includes('13.224.77')) color='dodgerblue';
if(ip.includes('74.125')) color='lightyellow';
let tr = td.closest('tr');
td.style.backgroundColor=color;
let timeTD=tr.querySelector('.time-column DIV');
let time=~~timeTD.textContent.replace('ms','');
if(time>100){
timeTD.parentNode.style.backgroundColor='orange';
}
});
colorRequests();
document.body.addEventListener('scroll',()=>{
console.log('scrolled');
colorRequests();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment