I took the reference of Python – Make every character/line random color print? and changed the text to ghost ascii art but the output is not printing the colored art but printing ascii code + the symbols used in the text.
import colorama
import random
text = """
.-----.
.' - - '.
/ .-. .-. \
| | | | | |
\ \o/ \o/ /
_/ ^ \_
| \ '---' / |
/ /`--. .--`\ \
/ /'---` `---'\ \
'.__. .__.'
`| |`
| \
\ '--.
'. `\
`'---. |
) /
\/
"""
colors = list(vars(colorama.Fore).values())
colored_chars = [random.choice(colors) + char for char in text]
print(''.join(colored_chars))
>Solution :
Try calling os.system('cls') before printing to the console with colors.
Also include r"" before your string to format it correctly (worked for me).
import colorama
import random
import os
text = r"""
.-----.
.' - - '.
/ .-. .-. \
| | | | | |
\ \o/ \o/ /
_/ ^ \_
| \ '---' / |
/ /`--. .--`\ \
/ /'---` `---'\ \
'.__. .__.'
`| |`
| \
\ '--.
'. `\
`'---. |
) /
\/
"""
os.system("cls")
colors = list(vars(colorama.Fore).values())
colored_chars = [random.choice(colors) + char for char in text]
print(''.join(colored_chars))
