# Nabokov's Synaesthesia # Adam Parrish # ap1607@nyu.edu # # Programming A to Z # Spring 2008 # ITP import sys class NabokovSynaesthesia(object): COLORS = { 'a': "#000", # polished ebony 'b': "#c90", # burnt sienna 'c': "#09f", # light blue 'd': "#ffe", # creamy white 'e': "#ff0", # yellow 'f': "#360", # "alder leaf" 'g': "#666", # "vulcanized rubber" 'h': "#c96", # "drab shoelace brown" 'i': "#ff0", # (also) yellow 'j': "#fc6", # pale rich rubbery orange 'k': "#336", # huckleberry 'l': "#fec", # "noodle-limp" 'm': "#fcc", # pink flannel 'n': "#eec", # oatmeal 'o': "#ffc", # "ivory-backed hand mirror" 'p': "#cf6", # unripe apple 'q': "#860", # brown 'r': "#443", # "sooty rag" 's': "#08f", # azure 't': "#990", # pistachio 'u': "#663", # brassy with an olive sheen 'v': "#cc9", # rose quartz 'w': "#464", # "dull green, combined somehow with violet" 'x': "#cce", # "steely" 'y': "#ff3", # bright golden yellow 'z': "#318", # thundercloud (indigo) } def transform(self, str): ret = '' for char in str: cstr = '' if char.lower() in self.COLORS: color = self.COLORS[char.lower()] cstr = '%s' \ % (color, color, char) else: cstr = char ret = ret + cstr return ret if __name__ == '__main__': # handle command line if len(sys.argv) == 3: input = open(sys.argv[1], 'r') output = open(sys.argv[2], 'w') elif len(sys.argv) == 1: input = sys.stdin output = sys.stdout else: sys.stderr.write("Usage: nabokov.py infile outfile\n") sys.stderr.write("(you can also use stdin and stdout)\n") sys.exit(1) vladimir = NabokovSynaesthesia() # translate and write each line output.write("
")
  for line in input:
    output.write(vladimir.transform(line))
  output.write("
")