-
Notifications
You must be signed in to change notification settings - Fork 0
/
AsciiArt.py
50 lines (40 loc) · 1.34 KB
/
AsciiArt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from string import ascii_uppercase as alphabet
'''
get_font is a function that reads the font.txt file and returns a dictionary
containing the font to apply (it takes no parameters)
'''
def get_font ():
with open ("font.txt", "r") as file:
file_content = file.read ()
rows = file_content.split ("\n")
font_dic = {}
for j in range (26):
letter = alphabet [j]
list_character = []
for i in range (8):
list_character.append (rows [j * 8 + i])
font_dic [letter] = list_character
file.close ()
return font_dic
'''
print_with_font is a function that prints a string
in a certain font contained in a dictionary that is returned by
the get_font function.
It takes one argument : text (string)
It returns None.
'''
def print_with_font (text):
text = text.upper ()
font_dic = get_font ()
for i in range (8):
for letter_index, letter in enumerate (text):
separator = " "
if letter in alphabet:
letter_chars = font_dic [letter]
current_letter_char = letter_chars [i]
print (current_letter_char, end = separator)
else:
print (letter, end = separator)
print()
if __name__ == "__main__":
print_with_font ("test")