forked from asweigart/the-big-book-of-small-python-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitmapmessage.py
52 lines (47 loc) · 2.39 KB
/
bitmapmessage.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
51
52
"""Bitmap Message, by Al Sweigart [email protected]
Displays a text message according to the provided bitmap image.
This code is available at https://nostarch.com/big-book-small-python-programming
Tags: tiny, beginner, artistic"""
import sys
# (!) Try changing this multiline string to any image you like:
# There are 68 periods along the top and bottom of this string:
# (You can also copy and paste this string from
# https://inventwithpython.com/bitmapworld.txt)
bitmap = """
....................................................................
************** * *** ** * ******************************
********************* ** ** * * ****************************** *
** ***************** ******************************
************* ** * **** ** ************** *
********* ******* **************** * *
******** *************************** *
* * **** *** *************** ****** ** *
**** * *************** *** *** *
****** ************* ** ** *
******** ************* * ** ***
******** ******** * *** ****
********* ****** * **** ** * **
********* ****** * * *** * *
****** ***** ** ***** *
***** **** * ********
***** **** *********
**** ** ******* *
*** * *
** * *
...................................................................."""
print('Bitmap Message, by Al Sweigart [email protected]')
print('Enter the message to display with the bitmap.')
message = input('> ')
if message == '':
sys.exit()
# Loop over each line in the bitmap:
for line in bitmap.splitlines():
# Loop over each character in the line:
for i, bit in enumerate(line):
if bit == ' ':
# Print an empty space since there's a space in the bitmap:
print(' ', end='')
else:
# Print a character from the message:
print(message[i % len(message)], end='')
print() # Print a newline.