numwarp by Logan

#!/usr/bin/python

import sys

font_str = r'''
/\
\ \
 \/
 \
  \
   
/\
 / 
 \/
/\
 /\
  /
 \
\/\
   
/ 
\/\
  /
/ 
\/\
 \/
/\
  \
   
/\
\/\
 \/
/\
\/\
'''

font_lines = font_str.strip().split('\n')
font = [font_lines[i:(i + 3)] for i in xrange(0, 30, 3)]
font[-1].append('   ')


def Mix(a, b):
  if len(a) < len(b):
    return Mix(b, a)
  buf = list(a)
  for i, c in enumerate(b):
    if c != ' ':
      buf[i] = c
  return ''.join(buf)


def draw(text):
  text = text.strip()
  lines = [''] * (2 * len(text) + 1)
  for x, c in enumerate(text):
    i = len(text) - x - 1
    r = i * 2
    c = int(c)
    lines[r] = Mix(lines[r], ' ' * 2 * x + font[c][0])
    lines[r + 1] = Mix(lines[r + 1], ' ' * 2 * x + font[c][1])
    lines[r + 2] = Mix(lines[r + 2], ' ' * 2 * x + font[c][2])
  for l in lines:
    print l


if __name__ == '__main__':
  for line in sys.stdin:
    draw(line)

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page