-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlevel_22.py
More file actions
44 lines (37 loc) · 1.08 KB
/
level_22.py
File metadata and controls
44 lines (37 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/env python
# coding=utf-8
# http://butter:fly@www.pythonchallenge.com/pc/hex/copper.html
# Draw points according to the image sequence.
from io import BytesIO
import requests
from PIL import Image
from PIL import ImageDraw
from PIL import ImageSequence
PREFIX = "http://butter:fly@www.pythonchallenge.com/pc/hex/"
url = PREFIX + 'white.gif'
def solve(something):
im = Image.open(BytesIO(something))
unknown = Image.new('RGB', im.size)
draw = ImageDraw.Draw(unknown)
cx, cy = 0, 100
for frame in ImageSequence.Iterator(im):
left, upper, _, _ = frame.getbbox()
dx = (left - 100) // 2
dy = (upper - 100) // 2
if cx:
draw.point((cx, cy))
cx += dx
cy += dy
if dx == dy == 0:
cx += 25
cy = 100
return unknown
def plot(im):
im.show()
if __name__ == "__main__":
r = requests.get(url)
something = r.content
answer = solve(something)
plot(answer)
# bonus
# http://butter:fly@www.pythonchallenge.com/pc/hex/bonus.html