def solveMaze(): # sys.setrecursionlimit(50000) maze = im.open('maze.png') # print maze.mode li = list(maze.getdata()) maze = chunks(li, 641) # path = [(0,639)] # print isPath(maze, path) # print len(path) # pickle.dump(path, open('maze-sol.dat', 'wb')) path = pickle.load(open('maze-sol.dat', 'rb')) # for pix in path: # maze[pix[0]][pix[1]] = PATH # new_img = list(itertools.chain(*maze)) # fim = im.new('RGBA',(641,641)) # fim.putdata(new_img) # fim.show() pathdata = [] for pix in path: pathdata.append(maze[pix[0]][pix[1]][0]) # print len(pathdata) # for dat in pathdata[:10:2]: # if dat != (0,0,0,255): # raise Exception('Assumption is wrong!') #we can skip every odd element in pathdata pathdata = pathdata[1::2] dat = ''.join(chr(x) for x in pathdata) print dat[:100] print len(dat) z = ZipFile(StringIO(dat)) print z.namelist() z.extractall(path='./ch24_files/') z.close()
def solveJigsaw(): wavdata = [] for i in xrange(1, 26): filename = DIR + str(i) + '.wav' wav = wave.open(filename, 'rb') wavdata.append(wav.readframes(NFRAMES)) wav.close() # now break up the data streams into pix sized chunks and draw the img new_img = list(list(() for i in xrange(300)) for i in xrange(300)) for i, wav in enumerate(wavdata): dat = list(ord(x) for x in wav) dat = pixify(dat) dat = chunks(dat, 60) place_piece(dat, new_img, i) print len(new_img) print len(new_img[0]) print new_img[0][0] new_img = list(chain(*new_img)) fim = Image.new('RGB', (60 * 5, 60 * 5)) fim.putdata(new_img) fim.show()
from PIL import Image as im from ch7 import chunks if __name__ == '__main__': img = im.open('cave.png') li = list(img.getdata()) print img.mode finlist = [] orig_list = li li = chunks(li, 640) rctr = 0 for row in li: ctr = 0 for pix in row: if (ctr % 2 != 0) and (rctr % 2 != 0): #odd if odd row finlist += [pix] elif (ctr % 2 == 0) and (rctr % 2 == 0): finlist += [pix] ctr += 1 rctr += 1 fim = im.new('RGB', (320, 480)) fim.putdata(finlist) fim.show()
marks = [] imgctr = 0 for img in imgs: img = img.convert('RGBA') li = list(img.getdata()) # print '\nCTR:', imgctr, '\n' imgctr += 1 # print img.mode # print img.size # print len(li) li = chunks(li,200) # print len(li[0]) # print len(li) rc = 1 for row in li: col = 1 for pix in row: if pix == (8,8,8,255): marks.append((rc-1, col-1)) col += 1 rc += 1
marks = [] imgctr = 0 for img in imgs: img = img.convert('RGBA') li = list(img.getdata()) # print '\nCTR:', imgctr, '\n' imgctr += 1 # print img.mode # print img.size # print len(li) li = chunks(li, 200) # print len(li[0]) # print len(li) rc = 1 for row in li: col = 1 for pix in row: if pix == (8, 8, 8, 255): marks.append((rc - 1, col - 1)) col += 1 rc += 1
from PIL import Image as im from ch7 import chunks if __name__ == '__main__': img = im.open('cave.png') li = list(img.getdata()) print img.mode finlist = [] orig_list = li li = chunks(li,640) rctr = 0 for row in li: ctr = 0 for pix in row: if (ctr%2 != 0) and (rctr%2!=0): #odd if odd row finlist += [pix] elif (ctr%2 == 0) and (rctr%2==0): finlist += [pix] ctr += 1 rctr+=1 fim = im.new('RGB',(320,480)) fim.putdata(finlist) fim.show()
if __name__ == '__main__': # To convert gif to png # img = im.open('mozart.gif') # new_img = im.new("RGBA", img.size) # new_img.paste(img) # new_img.save('mozart.png') # new_img.show() img = im.open('mozart.png') print img.mode img = list(img.getdata()) img = chunks(img,640) new_img = [] for row in img: for i in range(4,len(row)): if row[i] == (255, 0, 255, 255) and row[i] == row[i-1] and row[i] == row[i-2] and row[i] == row[i-3] and row[i] == row[i-4]: new_img.extend(row[i:] + row[:i]) # rctr = 0 # for row in li: # ctr = 0 # for pix in row: # if (ctr%2 != 0) and (rctr%2!=0): #odd if odd row # finlist += [pix] # elif (ctr%2 == 0) and (rctr%2==0):