|
| 1 | +import sys |
| 2 | + |
| 3 | +# (!) Try changing this multiline string to any image you like: |
| 4 | + |
| 5 | +# There are 68 periods along the top and bottom of this string: |
| 6 | +# (You can also copy and paste this string from |
| 7 | +# https://inventwithpython.com/bitmapworld.txt) |
| 8 | +bitmap = """ |
| 9 | +.................................................................... |
| 10 | + ************** * *** ** * ****************************** |
| 11 | + ********************* ** ** * * ****************************** * |
| 12 | + ** ***************** ****************************** |
| 13 | + ************* ** * **** ** ************** * |
| 14 | + ********* ******* **************** * * |
| 15 | + ******** *************************** * |
| 16 | + * * **** *** *************** ****** ** * |
| 17 | + **** * *************** *** *** * |
| 18 | + ****** ************* ** ** * |
| 19 | + ******** ************* * ** *** |
| 20 | + ******** ******** * *** **** |
| 21 | + ********* ****** * **** ** * ** |
| 22 | + ********* ****** * * *** * * |
| 23 | + ****** ***** ** ***** * |
| 24 | + ***** **** * ******** |
| 25 | + ***** **** ********* |
| 26 | + **** ** ******* * |
| 27 | + *** * * |
| 28 | + ** * * |
| 29 | +....................................................................""" |
| 30 | + |
| 31 | +print('Bitmap Message') |
| 32 | +print('Enter the message to display with the bitmap.') |
| 33 | +message = input('> ') |
| 34 | +if message == '': |
| 35 | + sys.exit() |
| 36 | + |
| 37 | +# Loop over each line in the bitmap: |
| 38 | +for line in bitmap.splitlines(): |
| 39 | + # Loop over each character in the line: |
| 40 | + for i, bit in enumerate(line): |
| 41 | + if bit == ' ': |
| 42 | + # Print an empty space since there's a space in the bitmap: |
| 43 | + print(' ', end='') |
| 44 | + else: |
| 45 | + # Print a character from the message: |
| 46 | + print(message[i % len(message)], end='') |
| 47 | + print() # Print a newline. |
0 commit comments