'''Transcentration01.py This program performs some setup prior to running a game of "Transcentration". It reads in a file containing a list of image file names, and then it reads in a list of transformation formulas. In the current version, these are assumed to be in a one-to-one correspondence, though actually there is no problem if there are more formulas than images. For each image on the list of images, the corresponding formula is taken from the list of formulas and a file name is constructed using the image file name and the first part (the 'name') of the formula. Next we check to see if a file with this constructed file name exists in the folder TRANSFORMED. If so, we skip this image and this formula and go on to the next one. If the file does NOT exist, we transform the image with its formula and create a new image file with the constructed name and put it in the TRANSFORMED folder. In this way, it will not be necessary to create any new image files when the game is actually played, since this program will have constructed them. (However, this could be called on demand by the game program to set up a custom arrangement.) Status: Working as of July 9, 2010 --S. T. ''' PATH = '../Transcentration/' # Read in a file containing a list of image files to use. image_list_file = open(PATH+'ORIGINALS/active-images-list.txt', 'r') image_files = image_list_file.readlines() formula_list_file = open(PATH+'TRANSFORMED/active-formulas-list.txt', 'r') formulas = formula_list_file.readlines() i = 0 for line in image_files: line = line[:-1] print line formula_line = formulas[i][:-1] i += 1 comment = True if formula_line[0]!='#': comment = False while comment: formula_line = formulas[i][:-1] i += 1 comment = True if formula_line[0]!='#': comment = False print formula_line pos = formula_line.find(':') formula_name = formula_line[:pos] formula = formula_line[pos+1:] transname = formula_name new_name = line[:-4]+'-'+transname+'.png' # Check to see if the transformed image file already exists. try: file = open(PATH+'TRANSFORMED/'+new_name, 'r'); exists = True except: exists = False # If not, then create it: if not exists: win1 = pmOpenTwo(PATH+'ORIGINALS/'+line) win2= win1+1 # pmCloneImage(win1) pmSetSource1(win1) pmSetDestination(win2) pmSetFormula(formula) pmCompute() pmSaveImageAs(win2, PATH+'TRANSFORMED/'+new_name); print 'Wrote image file: '+PATH+'TRANSFORMED/'+new_name else: print 'The file: '+PATH+'TRANSFORMED/'+new_name+' already exists.'