#!/usr/bin/env python """ fontforms.py - Discover the Art of Fonts Copyright 2008, Sean B. Palmer, inamidst.com Licensed under the Eiffel Forum License 2. """ import random, optparse alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' def rand(): for i in xrange(250): x, y = random.randint(50, 700), random.randint(50, 1000) rotate = round(random.uniform(0, 360), 2) scale = round(random.uniform(0.5, 3), 2) t = 'translate(%s, %s) rotate(%s) scale(%s)' % (x, y, rotate, scale) letter = random.choice(alpha) print '%s' % (t, letter) def cloud(): for i in xrange(320): x, y = random.randint(50, 700), random.randint(50, 1000) rotate = round(random.uniform(0, 360), 2) if i > 50: # Only use big characters away from the centre scale = round(random.uniform(0.5, 3), 2) else: scale = round(random.uniform(0.5, 1.8), 2) t = 'translate(%s, 0) rotate(%s) scale(%s)' % (i, rotate, scale) trans = 'translate(350, 500) rotate(%s) %s scale(-1, 1)' % (rotate, t) letter = random.choice(alpha) print '%s' % (trans, letter) def svg(opts): print '' print '' print '' print '' print '%s' % opts.font modes = {'random': rand, 'cloud': cloud} try: modes[opts.mode]() except KeyError, e: print >> sys.stderr, 'Error: You need to choose a valid mode' raise e print '' print '' def main(argv=None): parser = optparse.OptionParser('%prog [options]\n' + __doc__.strip()) parser.add_option('-f', '--font', metavar='name', default='Georgia', help='use this font for the output') parser.add_option('-m', '--mode', metavar='name', default='random', help='use this mode for the output') opts, args = parser.parse_args(argv) if args: print >> sys.stderr, 'Warning: ignoring arguments' svg(opts) if __name__ == '__main__': main()