[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/bjd1111/python/master/pythonchallenge/33.py [Back]  [Original]

# -*- coding: UTF-8 -*-

import Image
import math

beer = Image.open('beer2.png')
#
colors = beer.getcolors()
colors_len = len(colors)
data = list(beer.getdata())
colors_index = colors_len - 1
while colors_index > 0:
    #
    dim = math.sqrt(len(data))
    new_img = Image.new('1', (int(dim), int(dim)))
    #
    output = [item == colors[colors_index][1] for item in data]
    new_img.putdata(output)
    new_img.save('level33_%d.png'%(colors_index / 2))
    #
    eli_color_a = colors.pop(colors_index)[1]
    eli_color_b = colors.pop(colors_index - 1)[1]
    for k in xrange(len(data) - 1, -1, -1):
        if data[k] == eli_color_a or data[k] == eli_color_b:
            data.pop(k)
    colors_index -= 2

Web Proxy Viewer  |  New URL  |  Original Page