Print Snoopy To Screen

This snippet was posted originally at python-forum.org by redmarvel

#!/usr/bin/python
""" Print Snoopy to the Screen"""
# Marianne Williams 03 JUL 2007 Toronto, Ontario

import sys
import random

# spacing
S = []
S = [' ' * x for x in range(41)]
# uppercase letter X
X = []
X = ['X' * x for x in range(41)]
# asterisk
A = []
A = ['*' * x for x in range(41)]

# keys to exit the program
quitseq = 'q,x,end,quit,stop,exit,halt,off,' 
quitseq += quitseq.upper() # allow upper case versions
quitseq = quitseq.split(',') # change string to list

# default phrases
defphrase = []
defphrase.append('Curse You, Red Baron!')
defphrase.append("Yesterday I was a dog. Today I'm a dog. Tomorrow I'll probably still be a dog!")
defphrase.append('My aunt Marian was right, but I forgot what she said!')
defphrase.append('My life is full of unsuffered consequences!')
defphrase.append("Dead puppies aren't much fun!")
defphrase.append("Bring out the comfy chair!")
defphrase.append("Your mother was a hamster!")
defphrase.append("I don't like Spam!")
defphrase.append("I'm more interesting than a wet pussycat!")

# over word or maximum number of lines length
overword = []
overword.append("I'm a dog, blast you, not a dictionary!")
overword.append("Stop trying to suffocate me with words!")
overword.append("You have GOT to be kidding!")
overword.append('I am NOT going to repeat that, say it yourself!')
overword.append("Give me a bloody break you twit!")
overword.append("Information overload!!!")
overword.append("Yeah, right!")
overword.append("Are you nervy? Irritable? Deppressed? Tired of Life? Keep it up!")
overword.append("You silly bunt!")
overword.append("I wave my private parts at your aunties," + '\n'
                + "you cheesy lot of second-hand electric donkey bottom biters!")

# Prompt for a Phrase to be printed
print "Press the Enter key for Snoopy's default phrase"
Phrase = ''
try:
    Phrase = sys.argv[1]
except:
    # no Phrase found, prompt for it
    print
    Phrase = ''
    while not Phrase:
        Phrase = raw_input("Enter an angry phrase for Snoopy to say ")
        if not Phrase:
            Phrase = random.choice(defphrase)
        if Phrase in quitseq: sys.exit() # exit the program
# check to make sure the maximum word length is not longer than our line X 2
words = Phrase.split(' ')
x = 0
y = 0
for word in words:
    x = len(word)
    if x > y: y = x
if y > 42:
    Phrase = random.choice(overword)

# Word Wrapping Function stolen from the internet
def wrap(text, width):
    return reduce(lambda line, word, width=width: '%s%s%s' %
                  (line,
                   ' \n'[(len(line)-line.rfind('\n')-1
                         + len(word.split('\n',1)[0]
                              ) >= width)],
                   word),
                  text.split(' ')
                 )

Line = {} # set to blank dictionary
for x in range(11):
    Line[x] = ''

# Check length of phrase
if len(Phrase) < 22:
    if Phrase.count('\n') == 0:
        Llen = len(Phrase)
        Line[7] = S[2] + '_' * Llen
        Line[8] = ' /' + ' ' * Llen + '\\'
        Line[9] = '( ' + Phrase + ' )'
        Line[10] = ' \\' + '_' * 4 + S[2] + '_' * (Llen - 6) + '/'            
if not Line[10]:
    msg = Phrase[:]
    NewLine = wrap(msg,21)
    if NewLine.count('\n') > 8:
        msg = random.choice(overword)
        NewLine = wrap(msg,21)
    NewLine = NewLine.split('\n')
    NewLine.reverse()
    Line[10] = ' \\' + '_' * 4 + S[2] + '_' * 15 + '/'
    LNum = 9
    for word in NewLine:
        if len(word) > 21:
            word1 = word[21:]
            Line[LNum] = '| ' + word1.center(21) + ' |'
            LNum -= 1
            word = word[:21]
        TLine = word.center(21)
        Line[LNum] = '| ' + TLine + ' |'
        LNum -= 1
        if LNum == 1: break
    Line[LNum] = ' /' + S[21] + '\\'
    LNum -= 1
    Line[LNum] = S[2] + '_' * 21

# time for Snoopy to head into battle
print S[16] + X[4] + S[39] + Line[1]
print S[15] + 'X' + S[4] + X[2] + S[14] + S[23] + Line[2]
# top of snout
print S[14] + 'X' + S[2] + A[3] + S[2] + 'X' + S[16] + X[5] + S[15] + Line[3]
print S[13] + 'X' + S[2] + A[5] + S[2] + 'X' + S[12] + X[3] + S[5] + X[2] +  S[13] + Line[4]
print S[10] + X[4] + ' ' + A[5] + A[2] + ' ' + X[3] + S[5] + ' ' + X[4] + S[5] + S[5] + X[2] + S[11] + Line[5]
# top of nose
print S[8] + X[2] + S[3] + 'X' + ' ' + A[5] + '*' + S[2] + X[5] + X[4] + S[16] + X[2] + ' ' + X[3] + S[5] + Line[6]
print S[6] + X[2] + S[6] + 'X' + ' ' + A[4] + S[2] + 'X' + S[27] + X[5] + S[4] + Line[7]
# top of eye
print S[5] + 'X' + S[8] + X[2] + S[4] + X[2] + S[5] + '~' + S[22] + X[5] + S[4] + Line[8]
print S[4] + 'X' + S[9] + '//' + X[4] + S[7] + '@' + S[22] + X[4] + S[5] + Line[9]
print S[3] + 'X' + S[9] + '//' + S[3] + 'X' + S[29] + X[2] + S[9] + Line[10]
# top of open mouth
print S[2] + 'X' + S[9] + '//' + S[4] + 'X' + S[12] + X[16] + '/' + S[16] + '/ /'
print ' ' + 'X' + S[6] + X[3] + '//' + S[4] + 'X' + S[12] + 'X' + S[26] + '_' * 6 + '/ /'
print 'X' + S[6] + 'X' + S[3] + 'X' + S[5] + 'X' + S[11] + 'X' + S[27] + '_' * 7 + '/'
print 'X' + S[6] + 'X' + S[4] + 'X' + S[4] + 'X' + S[10] + 'X' 
# top of raised fist
print 'X' + S[6] + 'X' + S[4] + 'X' + S[4] + 'X' + S[9] + 'X' + S[20] + X[2]
print 'X' + S[7] + 'X' + S[3] + 'X' + S[4] + 'X' + S[9] + 'X' + S[17] + X[3] + S[2] + X[2]
print ' ' + 'X' + S[7] + X[3] + S[5] + 'X' + S[9] + 'X' + S[16] + 'X' + S[2] + 'X X' + S[2] + 'X'
print S[2] + 'X' + S[15] + 'X' + S[9] + 'X' + S[15] + X[2] + ' ' + 'X' + S[2] + X[4]
# bottom of open mouth
print S[3] + 'X' + S[15] + 'X' + S[9] + X[7] + '\\' + S[7] + X[2] + S[3] + X[2] + S[2] + 'X'
print S[4] + X[2] + S[14] + X[2] + S[14] + 'X' + S[7] + 'X' + S[4] + 'X' + S[2] + X[2]
# bottom of jaw
print S[6] + X[2] + S[14] + X[14] + '/' + S[7] + 'X' + S[4] + X[4]
print S[8] + X[3] + S[19] + A[3] + S[12] + 'X' + S[5] + 'X'
print S[11] + X[17] + ' ' + '*' + S[3] + '*' + S[10] + 'X' + S[5] + 'X'
print S[28] + '*' + S[3] + '*' + ' ' + 'X' + S[8] + 'X' + S[5] + 'X'
print S[27] + '*' + S[3] + '*' + S[3] + X[3] + S[4] + 'X' + S[5] + 'X'
print S[26] + '*' + S[3] + '*' + S[7] + X[4] + S[5] + 'X'
print S[26] + '*' + S[3] + '*' + S[9] + X[2] + S[4] + 'X'
# top of shoulder
print S[26] + '*' + S[3] + '*' + 'X X' + S[8] + X[4]
print S[25] + '*' + S[3] + '*' + ' ' + 'X' + S[2] + 'X' + S[9] + X[3]
print S[24] + '*' + S[3] + '*' + S[2] + 'X' + S[3] + 'X' + S[10] + X[2]
print S[23] + '*' + S[3] + '*' + S[3] + '*' + X[2] + S[2] + 'X' + S[10] + 'X'
print S[22] + '*' + S[3] + '*' + S[4] + '*' + S[2] + 'X' + S[3] + 'X' + S[9] + 'X'
# top of lowered fist
print S[21] + '*' + S[3] + '*' + S[4] + A[2] + S[3] + 'X' + S[3] + X[4] + S[5] + 'X'
print S[20] + '*' + S[3] + '*' + S[4] + A[3] + S[3] + X[2] + S[5] + 'X' + S[5] + 'X'
print S[19] + '*' + S[3] + '*' + S[4] + A[4] + S[3] + 'X' + S[5] + X[2] + S[5] + 'X'
print S[19] + '*' + S[3] + '*' + S[4] + A[4] + S[4] + X[2] + S[3] + 'X' + S[5] + X[2]
print S[19] + '*' + S[3] + '*' + S[4] + A[3] + S[6] + X[4] + S[6] + 'X'
print S[18] + '*' + S[3] + A[2] + S[4] + A[2] + S[16] + 'X'
print S[17] + '*' + S[3] + A[3] + S[5] + '*' + S[15] + 'X'
# top of legs
print S[16] + '*' + S[3] + '* ' * 2 + S[5] + 'X' + '*' + S[12] + X[3]
print S[15] + '*' + S[3] + '* ' * 2 + S[7] + X[4] + S[5] + 'X' + S[5] + 'X'
print S[14] + '* ' * 5 + S[9] + 'X' + S[5] + 'X' + S[5] + 'X'
# top of toes
print S[14] + '* ' * 5 + S[9] + 'X' + S[5] + 'X' + S[6] + X[5] + 'x'
print S[13] + '* ' * 5 + S[6] + 'x' + X[4] + S[6] + X[5] + 'x' + S[5] + 'Xx'
print S[14] + '* ' * 5 + S[4] + 'xX' + S[15] + 'Xx' + X[4] + 'x'
print S[13] + '* ' * 5 + S[6] + 'xX' + X[14] + 'x'
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.