#!/usr/bin/env python # Christmas tree generator. import sys, random if len(sys.argv) < 4: print 'Usage:', sys.argv[0], '[height] [trunk height] [trunk width] [ornament spread]' sys.exit(1) height = int(sys.argv[1]) theight = int(sys.argv[2]) twidth = int(sys.argv[3]) spread = int(sys.argv[4]) cwidth = 1 # print star nspaces = height - (cwidth / 2) print ' ' * nspaces + '\x1b[1;33m*\x1b[0m' # print tree and ornaments for row in xrange(height): line = '' for i in xrange(cwidth): if i % 2 == 0: line += '\x1b[1;32m^\x1b[0m' else: if random.randint(0, spread) == 0: # place an ornament color = random.choice(['33', '34', '35', '36', '38']) bright = random.choice(['0;', '1;']) shape = random.choice('o*@0') line += '\x1b[' + bright + color + 'm' + shape + '\x1b[0m' else: line += ' ' nspaces = height - (cwidth / 2) print ' ' * nspaces + line cwidth += 2 # print trunk nspaces = height - (twidth / 2) for i in xrange(theight): print ' ' * nspaces + '\x1b[0;33m|\x1b[0m' * twidth # print snow print '\x1b[1;37m~\x1b[0m' * (height * 2 + 2) # reset colors print '\x1b[0m'