ASCII Art Generator Script
This script reads numerical ASCII values from a text file, converts them into characters, and applies formatting to visualize them as colored ASCII art. It supports custom line breaks and highlights specific ASCII characters with unique background colors.
# coding: utf-8 import numpy as np def get_ascii_map(path, rb=14): fgGreen = '\u001b[32m' reset = '\u001b[0m' bgMagenta = '\u001b[45m' bgRed = '\u001b[41m' with open(path) as f: contents = [int(x) for x in f.read().split()] codes = np.array(contents) breaks = np.argwhere(codes==10) breaks = np.insert(breaks, 0, 0) rows = [codes[le:re+1] for le, re in zip(breaks[:-1], breaks[1:])] outStr = '' for row in rows: newLine = True lines = 0 for idx, code in enumerate(row): bg = '' if newLine: for i in range(rb+1): outStr += f"{bgMagenta}{lines*(rb+1) + i+1:<7}{reset}" if i % rb == 0 and i != 0: outStr += '\n' newLine = False if code == 10: outCode = '\\n' outStr += f"{code}: {bg}{fgGreen}{outCode:>2}{reset} " outStr += "\n\n\n" else: if code == 32: outCode = "\\s" bg = bgRed else: outCode = chr(code) outStr += f"{code}: {bg}{fgGreen}{outCode:>2}{reset} " if idx % rb == 0 and idx != 0: newLine = True outStr += '\n' lines += 1 return outStr asciiMap = get_ascii_map('recordDump.txt') with open('oneRecordAsciiDump.txt', 'w') as f: f.write(asciiMap)