Superimpose.py

From XPUB & Lens-Based wiki

Description

Superimposes ASCII art

Usage

figlet hello > hello.txt
figlet world > world.txt
python superimpose hello.txt world.txt

produces...

 _          _ _     _     _ 
__|__   _____| _ __| | __| |
\ \_/\ / / _ \||'__|\|/ _` |
|\|V| V /_(_)||||(_| | (_| |
|_\_/\_/_\___/|_|__|_|\__,_|

Code

import itertools
import sys

for x, y in zip(open(sys.argv[1]), open(sys.argv[2])):
    for xc, yc in itertools.izip_longest(x.rstrip('\r\n'), y.rstrip('\r\n'), fillvalue=' '):
        if yc == ' ':
            sys.stdout.write(xc);
        else:
            sys.stdout.write(yc);
    sys.stdout.write('\n')

Source: Alexandre Leray