Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for English to Braille Translator by Tinus_Trotyl
BINREPR = ( 0, 1, 3, 9, 25, 17, 11, 27, 19, 10, 26, 5, 7, 13, 29, 21,
15, 31, 23, 14, 30, 37, 39, 62, 45, 61, 53, 47, 63, 55, 46, 26 )
def codex(ch):
if ch == ' ': return (-1, 0)
if 'a' <= ch <= 'z': return (-1, BINREPR[ord(ch) - ord('a') + 1])
if 'A' <= ch <= 'Z': return (32, BINREPR[ord(ch) - ord('A') + 1])
if '0' <= ch <= '9': return (60, BINREPR[ord(ch) - ord('0') if ch != '0' else 10])
return (-1, {' ': 0, ',': 2, '.': 50, '-': 18, '?': 38, '_': 36, '!': 22}[ch])
def boxed(ind):
box = [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0 ,0]]
for p in range(6):
ind, bit = divmod(ind, 2)
x, y = ((0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2))[p]
box[y][x] = bit
return box
def braille_page(txt):
lines = [[], [], []]
def writel(box):
for y in (0, 1, 2):
lines[y] = lines[y] + box[y]
while txt:
ch, txt = txt[0], txt[1:]
indicator, coded = codex(ch)
if indicator >= 0: writel(boxed(indicator))
writel(boxed(coded))
page = []
while lines[0]:
for y in (0, 1, 2):
page.append(lines[y][:29])
if len(lines[y][:30]):
page[-1] = page[-1] + [0 for i in range(29 - len(lines[y][:30]))]
lines[y] = (lines[y][30:])
if lines[0]:
page.append([0 for _ in page[-1]])
#if not len(page) % 4:
# page = page[:len(page) - 1]
if len(page) == 3:
while page[0][-3:] == page[1][-3:] == page[2][-3:] == [0, 0, 0]:
page[0], page[1], page[2] = page[0][:-3], page[1][:-3], page[2][:-3]
return page
Nov. 19, 2018