Created
January 9, 2023 09:25
-
-
Save Grissess/d61c9f4faa73e30085cdb6b2cfcce91c to your computer and use it in GitHub Desktop.
A successor, in name only, to https://gist.github.com/Grissess/6af0bcb8fe46e81b9a5f39bed03b9271 .
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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