The Python Challenge – Level 22

http://www.pythonchallenge.com/pc/hex/copper.html

위 페이지의 소스를 보면 아래와 같은 주석이 있다.

<!-- or maybe white.gif would be more bright-->

white.gif 파일을 좀 더 밝게 해란다. 또 PIL을 이용해야 하는 문제인가보다. white.gif 파일을 확인하여 보면 gif로 애니메이션 파일이다. 각 프레임별로 이미지를 뽑아서 밝기를 높혀보면 점이 나오는 것을 알 수 있다. 이 점들이 움직이는 대로 선을 그려 보면 문자가 나온다...

#!c:\python26\python.exe
import Image, ImageEnhance, ImageDraw

im = Image.open('white.gif')
list = []
try:
    while 1:
        im.seek(im.tell()+1)
        enhancer = ImageEnhance.Brightness(im)
        bright_im = enhancer.enhance(9999.9)
        for x in range(im.size[0]):
            for y in range(im.size[1]):
                data = im.getpixel((x, y))
                if data != 0:
                    list.append((x - 100, y - 100))
except EOFError:
    pass

im = Image.new('RGB', (500, 500))
draw = ImageDraw.Draw(im)
plus = 30
start = (plus, plus)
for x in list:
    if x == (0, 0):
        plus += 80
        start = (30 + plus, 30)
        continue

    end = (start[0] + x[0], start[1] + x[1])
    draw.line((start, end), fill=128)
    start = end
im.show()

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다