#!/usr/bin/python
#
# First line tells unix-like os's what interpreter to use for this script.
# The '#!' pair of characters is called 'shebang' or 'hashbang'
# (see 'http://en.wikipedia.org/wiki/Shebang_(Unix)'  )

# smiley_gen.py by Nadeem Abdul Hamid
#
# This program demonstrates basic features of Python: functions,
# lists, variables, strings, etc.


"""
This program will generate a bunch of possible text smiley faces
based on initial lists of eyes, nose, and mouth characters
"""

def getSmileys():
    # setup lists of individual features
    eyes = [ ':', ';', '8' ]
    noses = [ '', '-', '+', '<', '\'', '=' ]

    mouths = 'poO)]}({[/\\>|'
    mouths = [ mouths[i] for i in range(len(mouths)) ]
    mouths += [ '()', '[]', '{}', '<>', 'X', 'x' ]

    # add elongations to noses
    extras = []
    for nose in noses:
        extras.append( nose + '=' );
	extras.append( '=' + nose );
    noses += extras;

    # build list of all possible combinations
    smilies = []
    for eye in eyes:
	for mouth in mouths:
		for nose in noses:
			smilies.append( eye + nose + mouth );

    return smilies;


def formatFields( fields, numPerLine=10, fieldWidth=7 ):
    lines = []    # list of lines
    line = "";    # the current line
    count = 0;
    formatStr = '%' + str(fieldWidth) + 's';   # need to convert int to string
                                               # in order to concatenate
    for field in fields:
        line += formatStr % field
        count += 1
        if count == numPerLine:
            lines.append( line )
            line = ""
            count = 0
    if line != "":       # any leftover stuff on the last line
        lines.append( line );
    return lines;


def main():
    for line in formatFields( getSmileys(), fieldWidth=8 ):
        print line;
        

# this idiom allows this file to run as a standalone
# script as well as be included (imported) as a module
# in other scripts/programs without running this stuff
if __name__ == '__main__':
    main()

    
