Files / uploads /Nolan /IMGGG.py
lea97338's picture
Upload 66 files
6e9e3f1 verified
Raw
History Blame Contribute Delete
1.62 kB
# 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 = [
"<!DOCTYPE html>",
"<html>",
"<head>",
"<meta charset='UTF-8'>",
"<style>",
"body { background: black; margin: 0; padding: 0; }",
"pre { font-family: monospace; font-size: 6px; line-height: 6px; }",
"</style>",
"</head>",
"<body><pre>"
]
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"<span style='color: rgb({gray},{gray},{gray})'>{ch}</span>"
else:
# caractères hors table : on les affiche en blanc
html_line += f"<span style='color: rgb(255,255,255)'>{ch}</span>"
html.append(html_line)
html.append("</pre></body></html>")
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()