|
1 |
| -from PIL import Image, ImageDraw |
| 1 | +from PIL import Image |
| 2 | +from PIL import ImageSequence |
| 3 | +import turtle, time |
2 | 4 |
|
3 | 5 |
|
4 | 6 | def main():
|
5 |
| - im, width, height = first_step() |
6 |
| - second_step(im, width, height) |
7 |
| - |
8 |
| - |
9 |
| -def first_step(): |
10 |
| - im = Image.open("copper/white.gif") |
11 |
| - size = im.size |
12 |
| - width = size[0] |
13 |
| - height = size[1] |
14 |
| - return im, width, height |
15 |
| - |
16 |
| - |
17 |
| -def second_step(im, width, height): |
18 |
| - pass |
| 7 | + file_path = "copper/white.gif" |
| 8 | + pixels = first_step(file_path) |
| 9 | + """ |
| 10 | + pixels = [(100, 100), (100, 102), (100, 102), (100, 102), (100, 102), (100, 102), (100, 102), (100, 102), |
| 11 | + (100, 102), (102, 102), (102, 100), (102, 100), (102, 100), (102, 100), (102, 100), (102, 100), |
| 12 | + (102, 100), (102, 98), (100, 98), (100, 98), (100, 98), (98, 98), (98, 100), (98, 100), (98, 100), |
| 13 | + (98, 100), (98, 100), (98, 100), (98, 102), (100, 100), (98, 98), (98, 98), (98, 100), (98, 100), |
| 14 | + (98, 100), (98, 100), (98, 100), (98, 102), (98, 102), (98, 102), (100, 102), (100, 102), (102, 102), |
| 15 | + (102, 102), (102, 102), (102, 100), (102, 100), (102, 100), (102, 100), (102, 100), (102, 98), (102, 98), |
| 16 | + (102, 98), (100, 98), (100, 98), (100, 100), (100, 102), (100, 102), (100, 102), (100, 102), (100, 102), |
| 17 | + (100, 102), (100, 102), (102, 100), (100, 98), (100, 98), (100, 98), (102, 98), (102, 98), (102, 98), |
| 18 | + (102, 98), (102, 100), (102, 100), (102, 102), (102, 102), (102, 102), (100, 102), (100, 102), (100, 102), |
| 19 | + (100, 102), (100, 100), (100, 102), (100, 102), (100, 102), (100, 102), (100, 102), (100, 102), |
| 20 | + (102, 102), (102, 100), (102, 100), (102, 100), (102, 100), (102, 100), (102, 100), (102, 98), (100, 98), |
| 21 | + (100, 98), (100, 98), (100, 98), (100, 98), (100, 98), (100, 100), (98, 98), (98, 100), (98, 100), |
| 22 | + (98, 100), (98, 100), (98, 100), (98, 100), (98, 100), (98, 102), (100, 102), (100, 102), (102, 102), |
| 23 | + (102, 100), (102, 100), (102, 100), (102, 100), (102, 100), (102, 100), (102, 100), (102, 102), |
| 24 | + (100, 102), (100, 102), (98, 102), (98, 100), (98, 100), (98, 100), (98, 100), (98, 100), (98, 100), |
| 25 | + (98, 100), (98, 98)] |
| 26 | + """ |
| 27 | + second_step(pixels) |
| 28 | + |
| 29 | + |
| 30 | +def first_step(file_path): |
| 31 | + im = Image.open(file_path) |
| 32 | + pixels = [] |
| 33 | + for frame in ImageSequence.Iterator(im): |
| 34 | + size = frame.size |
| 35 | + width = size[0] |
| 36 | + height = size[1] |
| 37 | + for x in range(width): |
| 38 | + for y in range(height): |
| 39 | + pixel = frame.getpixel((x, y)) |
| 40 | + if pixel != 0: |
| 41 | + pixels.append((x, y)) |
| 42 | + print(pixels) |
| 43 | + return pixels |
| 44 | + |
| 45 | + |
| 46 | +def second_step(pixels): |
| 47 | + EXP = 10 |
| 48 | + x = y = 0 |
| 49 | + for pilx, pily in pixels: |
| 50 | + dx = (pilx - 100) // 2 |
| 51 | + dy = (100 - pily) // 2 |
| 52 | + x += dx * EXP |
| 53 | + y += dy * EXP |
| 54 | + turtle.goto(x, y) |
| 55 | + if dx == dy == 0: |
| 56 | + time.sleep(1) |
| 57 | + turtle.reset() |
| 58 | + x = y = 0 |
19 | 59 |
|
20 | 60 |
|
21 | 61 | if __name__ == "__main__":
|
|
0 commit comments