Skip to content

Instantly share code, notes, and snippets.

@Grissess
Created January 9, 2023 09:25
Show Gist options
  • Save Grissess/d61c9f4faa73e30085cdb6b2cfcce91c to your computer and use it in GitHub Desktop.
Save Grissess/d61c9f4faa73e30085cdb6b2cfcce91c to your computer and use it in GitHub Desktop.
import argparse
MAP = {
'A': [' * ', ' * * ', '*****', '* *', '* *'],
'B': ['*** ', '* *', '*** ', '* *', '*** '],
'C': ['****', '* ', '* ', '* ', '****'],
'D': ['** ', '* * ', '* *', '* * ', '** '],
'E': ['****', '* ', '****', '* ', '****'],
'F': ['****', '* ', '*** ', '* ', '* '],
'G': ['*****', '* ', '* ***', '* *', '*****'],
'H': ['* *', '* *', '****', '* *', '* *'],
'I': ['***', ' * ', ' * ', ' * ', '***'],
'J': ['****', ' * ', ' * ', '* * ', ' * '],
'K': ['* *', '* * ', '** ', '* * ', '* *'],
'L': ['* ', '* ', '* ', '* ', '****'],
'M': [' * * ', '* * *', '* * *', '* *', '* *'],
'N': ['* *', '** *', '* * *', '* **', '* *'],
'O': ['****', '* *', '* *', '* *', '****'],
'P': ['*** ', '* *', '*** ', '* ', '* '],
'Q': [' ** ', '* *', '* *', '* **', ' ***'],
'R': ['*** ', '* *', '*** ', '* * ', '* *'],
'S': [' *** ', '* ', ' *** ', ' *', ' *** '],
'T': ['***', ' * ', ' * ', ' * ', ' * '],
'U': ['* *', '* *', '* *', '* *', ' ** '],
'V': ['* *', '* *', ' * * ', ' * * ', ' * '],
'W': ['* *', '* *', '* * *', '* * *', ' * * '],
'X': ['* *', ' * * ', ' * ', ' * * ', '* *'],
'Y': ['* *', '* *', ' * ', ' * ', ' * '],
'Z': ['****', ' *', ' * ', ' * ', '****'],
'0': [' ** ', '* *', '* *', '* *', ' ** '],
'1': [' ** ', ' * ', ' * ', ' * ', '****'],
'2': [' ** ', '* *', ' * ', ' * ', '****'],
'3': ['*** ', ' *', ' ** ', ' *', '*** '],
'4': [' * ', ' ** ', '* * ', '****', ' * '],
'5': ['****', '* ', '*** ', ' *', '*** '],
'6': [' **', ' * ', '*** ', '* *', ' ** '],
'7': ['****', ' *', ' * ', ' * ', '* '],
'8': [' ** ', '* *', ' ** ', '* *', ' ** '],
'9': [' ** ', '* *', ' ***', ' * ', ' * '],
':': [' ', '*', ' ', '*', ' '],
';': [' ', '*', ' ', '*', '*'],
'.': [' ', ' ', ' ', ' ', '*'],
',': [' ', ' ', ' ', '*', '*'],
"'": ['*', '*', ' ', ' ', ' '],
'"': ['* *', '* *', ' ', ' ', ' '],
' ': [' ', ' ', ' ', ' ', ' '],
'-': [' ', ' ', '**', ' ', ' '],
}
DEFAULT = ['* *', '* *', ' ', '* *', '* *']
parser = argparse.ArgumentParser(description="Make block letters.")
parser.add_argument('text', help='Text to display')
parser.add_argument('--spacing', type=int, default=1, help='Space between letters')
parser.add_argument('--mark', '-m', default='*', help='Character to display when pixel is set')
parser.add_argument('--space', '-s', default=' ', help='Character to display when pixel is clear')
parser.add_argument('--hide-missing', action='store_true', help='Don\'t show missing characters')
parser.add_argument('--scale', type=int, default=1, help='Scale of the blocks')
def justify(blocks):
width = max([len(row) for row in blocks])
for idx, row in enumerate(blocks):
if len(row) < width:
blocks[idx] += ' ' * (width - len(row))
def concat(blocks, block):
while len(block) > len(blocks):
blocks.append('')
justify(blocks)
for idx in range(len(blocks)):
blocks[idx] += block[idx]
def shift(blocks, amt, char=' '):
justify(blocks)
for idx in range(len(blocks)):
blocks[idx] += char * amt
def block(text, mark='*', space=' ', spacing=1, hide=False):
blocks = []
dfl = None if hide else DEFAULT
for idx, ch in enumerate(text):
block = MAP.get(ch, dfl)
if block is not None:
bk = [''.join(mark if i == '*' else space for i in s) for s in block]
concat(blocks, bk)
shift(blocks, spacing, space)
return blocks
def scale(blocks, fac):
return [''.join(c * fac for c in s) for s in blocks for rep in range(fac)]
def main():
args = parser.parse_args()
blocks = block(args.text, args.mark, args.space, args.spacing, args.hide_missing)
if args.scale != 1:
blocks = scale(blocks, args.scale)
for line in blocks:
print(line)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment