Skip to content

Instantly share code, notes, and snippets.

@jo-lang
Last active November 17, 2022 11:44
Show Gist options
  • Save jo-lang/0b31de57a5d33ed171c1295e992db55e to your computer and use it in GitHub Desktop.
Save jo-lang/0b31de57a5d33ed171c1295e992db55e to your computer and use it in GitHub Desktop.
a braille text generator for drawbot
# a simple script to generate pdfs of (german) text converted to braille.
# this script need the drawbot app!
# This follows the DIN 32976
# a list of words
words = [
'This should output braille',
]
dot_s = 16 # the dot size 1.6mm
g_wdth = 66 # the with of a character (including the spacing): 6.6mm
gap = 27 # the gap between the center of two dots: 2.7mm
factor = 0.2835 # this factor is to scale drawbots pixel units to mm units
# the dictionary with the dots pattern for each character
abc = {
'A': (1,),
'B': (1, 2),
'C': (1, 4),
'D': (1, 4, 5),
'E': (1, 5),
'F': (1, 2, 4),
'G': (1, 2, 4, 5),
'H': (1, 2, 5),
'I': (2, 4),
'J': (2, 4, 5),
'K': (1, 3),
'L': (1, 2, 3),
'M': (1, 3, 4),
'N': (1, 3, 4, 5),
'O': (1, 3, 5),
'P': (1, 2, 3, 4),
'Q': (1, 2, 3, 4, 5),
'R': (1, 2, 3, 5),
'S': (2, 3, 4),
'T': (2, 3, 4, 5),
'U': (1, 3, 6),
'V': (1, 2, 3, 6),
'W': (2, 4, 5, 6),
'X': (1, 3, 4, 6),
'Y': (1, 3, 4, 5, 6),
'Z': (1, 3, 5, 6),
' ': (),
}
shifts = {
1 : (0, 0),
2 : (0, 1),
3 : (0, 2),
4 : (1, 0),
5 : (1, 1),
6 : (1, 2),
}
def draw_glyph(char):
dots = abc[char]
for d in dots:
x_s, y_s = shifts[d]
oval(x_s * gap - dot_s/2, -y_s * gap - dot_s/2, dot_s, dot_s )
def draw_word(word):
for char in word:
draw_glyph(char)
translate(g_wdth)
for word in words:
PW = g_wdth * len(word)
PH = gap * 2 + dot_s
newPage(PW * factor, PH * factor)
scale(factor)
translate(dot_s/2, gap*2+dot_s/2)
cmykFill(0, 0, 0, 1)
draw_word(word.upper())
# saveImage(f'braillepdfs/{word}__.pdf', multipage=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment