1"""Bitmap Message, by Al Sweigart al@inventwithpython.com
2Displays a text message according to the provided bitmap image.
3This code is available at https://nostarch.com/big-book-small-python-programming
4Tags: tiny, beginner, artistic"""
5
6import sys
7
8# (!) Try changing this multiline string to any image you like:
9
10# There are 68 periods along the top and bottom of this string:
11# (You can also copy and paste this string from
12# https://inventwithpython.com/bitmapworld.txt)
13bitmap = """
14....................................................................
15 ************** * *** ** * ******************************
16 ********************* ** ** * * ****************************** *
17 ** ***************** ******************************
18 ************* ** * **** ** ************** *
19 ********* ******* **************** * *
20 ******** *************************** *
21 * * **** *** *************** ****** ** *
22 **** * *************** *** *** *
23 ****** ************* ** ** *
24 ******** ************* * ** ***
25 ******** ******** * *** ****
26 ********* ****** * **** ** * **
27 ********* ****** * * *** * *
28 ****** ***** ** ***** *
29 ***** **** * ********
30 ***** **** *********
31 **** ** ******* *
32 *** * *
33 ** * *
34...................................................................."""
35
36print('Bitmap Message, by Al Sweigart al@inventwithpython.com')
37print('Enter the message to display with the bitmap.')
38message = input('> ')
39if message == '':
40 sys.exit()
41
42# Loop over each line in the bitmap:
43for line in bitmap.splitlines():
44 # Loop over each character in the line:
45 for i, bit in enumerate(line):
46 if bit == ' ':
47 # Print an empty space since there's a space in the bitmap:
48 print(' ', end='')
49 else:
50 # Print a character from the message:
51 print(message[i % len(message)], end='')
52 print() # Print a newline.