# ascii_to_html.py # Lit un fichier ASCII et génère un aperçu HTML coloré CHARS = " #%&WMBO0QC|/\\(){}[]?+;:,. " def load_ascii(path): with open(path, "r", encoding="utf-8") as f: return f.read().splitlines() def ascii_to_html(ascii_lines, output_file="ascii_preview.html"): html = [ "", "", "
", "", "", "", ""
]
for line in ascii_lines:
html_line = ""
for ch in line:
if ch in CHARS:
intensity = CHARS.index(ch) / (len(CHARS) - 1)
gray = int(intensity * 255)
html_line += f"{ch}"
else:
# caractères hors table : on les affiche en blanc
html_line += f"{ch}"
html.append(html_line)
html.append("")
with open(output_file, "w", encoding="utf-8") as f:
f.write("\n".join(html))
def main():
input_file = "input_ascii.txt" # ton ASCII existant
output_file = "ascii_preview.html" # aperçu coloré
ascii_lines = load_ascii(input_file)
ascii_to_html(ascii_lines, output_file)
print(f"HTML généré : {output_file}")
if __name__ == "__main__":
main()