The Python Challenge – Level 14

http://www.pythonchallenge.com/pc/return/italy.html

빵그림과 이상한 이미지를 하나 주어주고 풀라고 한다. 해당 페이지 소스를 보면 아래와 같은 힌트가 있다.

<!-- remember: 100*100 = (100+99+99+98) + (...  -->

빵그림이 동그랗게 되어 있으므로 처음 아래 이상한 이미지를 처음 100 픽셀 짤라 맨 우측에 붙이고(빨간부분), 그다음 99 픽셀을 짤라 하단에 붙이고(파란부분), 다음 99 픽셀을 짤라 좌측에 붙이고(노란부분) 이런식으로 조금씩 짤라서 안쪽으로 만들어 나가면 아래와 같은 이미지가 나온다.


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

im = Image.open('wire.png')
tmp = Image.new('RGB', (100, 100), 'black')

def first(pos, posX, posY, round):
    for x in range(posX):
        data = im.getpixel((x+pos, 0))
        tmp.putpixel((posY-1, x+round), data)

def second(pos, posX, posY, round):
    count = posX - 1
    for x in range(posX):
        data = im.getpixel((x+pos, 0))   
        tmp.putpixel((count+round, posY), data)
        count -= 1

def third(pos, posX, round):
    count = posX - 1
    for x in range(posX):
        data = im.getpixel((x+pos, 0))
        tmp.putpixel((round, count+round), data)
        count -= 1

def fourth(pos, posX, round):
    for x in range(posX):
        data = im.getpixel((x+pos, 0))
        tmp.putpixel((x+1+round, round), data)

pos = 0
x = 100
y = 100
for round in range(50):
    first(pos, x, y, round)
    pos += x
    x -= 1
    y -= 1

    second(pos, x, y, round)
    pos += x

    third(pos, x, round)
    pos += x
    x -= 1

    fourth(pos, x, round)
    pos += x

tmp.show()

이건 너무 어렵군 -_-

답글 남기기

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