Skip to content

Instantly share code, notes, and snippets.

@loisaidasam
Last active October 7, 2016 18:17
Show Gist options
  • Select an option

  • Save loisaidasam/4211d281d61eb1c902fa8e59b0405b41 to your computer and use it in GitHub Desktop.

Select an option

Save loisaidasam/4211d281d61eb1c902fa8e59b0405b41 to your computer and use it in GitHub Desktop.
[Monthly Challenge #11 - October, 2016] - Procedural Ghosts and Jack-o-Lanterns!

https://www.reddit.com/r/proceduralgeneration/comments/55xkud/monthly_challenge_11_october_2016_procedural/

The winner of last month's competition wasn't around to give a suggestion on topic, so this is what I came up with! It's October again! With all this spooky stuff abound I thought we could have some festivities of our own. Jack-o-lanterns and ghosts are just begging to be procedurally generated, but if you want to do bats or skeletons or something that's OK too as long as it's halloween themed!

===

My solution is an ASCII ghost that travels back and forth across your terminal randomishly. Happy Halloween!

ASCII ghost design via http://www.ascii-code.com/ascii-art/mythology/ghosts.php

import random
import time
'''
Ghost design via http://www.ascii-code.com/ascii-art/mythology/ghosts.php
___
_/ @@\
( \ O/__
\ \__)
/ \
/ _\
`"""""``
'''
GHOST = '''
___
_/ eyes\\
( \\ mouth/__
\\ \__)
/ \\
/ _\\
`"""""``
'''
GHOST_FLIPPED = '''
___
/eyes \\_
__\\mouth / )
(__/ /
/ \\
/_ \\
``""""`
'''
TERM_BOUNDARY_MIN = 0
TERM_BOUNDARY_MAX = 80
EYES_OPTIONS = (
'..',
'oo',
'@@',
'66',
'^^',
)
MOUTH_OPTIONS = (
'0',
'-',
'O',
'^',
'~',
'm',
)
def print_ghost(flip, spaces, eyes, mouth):
ghost = flip and GHOST or GHOST_FLIPPED
for line in ghost.split("\n"):
if spaces:
for space in xrange(spaces):
line = " " + line
print line.replace('eyes', eyes).replace('mouth', mouth)
def main():
spaces = 0
add = 5
boundary = TERM_BOUNDARY_MAX
eyes = random.choice(EYES_OPTIONS)
mouth = random.choice(MOUTH_OPTIONS)
while True:
spaces += add
flip = add > 0
print_ghost(flip, spaces, eyes, mouth)
if (add > 0 and spaces >= boundary) or (add < 0 and spaces <= boundary):
if add > 0:
boundary = random.randint(TERM_BOUNDARY_MIN, spaces)
else:
boundary = random.randint(spaces, TERM_BOUNDARY_MAX)
add *= -1
eyes = random.choice(EYES_OPTIONS)
mouth = random.choice(MOUTH_OPTIONS)
time.sleep(0.2)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment