Created
December 8, 2020 01:49
-
-
Save EllieTheYeen/43706fda3f3a3155755883aa53fa57a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from PIL import Image | |
import numpy as np | |
width, height = 800, 600 | |
grid = np.zeros((height, width), dtype=np.uint8) | |
x = y = int(width / 2) | |
d = 0 | |
imgs = [] | |
for i in range(10): | |
for a in range(100000): | |
if grid[y, x]: | |
d -= 1 | |
else: | |
d += 1 | |
d %= 4 | |
#if d < 0: d = 3 | |
#elif d > 3: d = 0 | |
grid[y, x] = 1 - grid[y, x] | |
#print(grid[x, y]) | |
if d == 0: y -= 1 | |
elif d == 1: x += 1 | |
elif d == 2: y += 1 | |
else: x -= 1 | |
x %= width | |
y %= height | |
#if x >= width: x = 0 | |
#elif x < 0: x = width - 1 | |
#elif y >= height: y = 0 | |
#elif y < 0: y = height - 1 | |
#print(x, y, d) | |
ia = ((1 - grid) * 255).repeat(3).reshape(height, width, 3) | |
i = Image.fromarray(ia) | |
imgs.append(i) | |
os.chdir(os.path.split(__file__)[0] or '.') | |
print('Sum is', grid.sum()) | |
imgs[0].save('output.gif', loop=0, save_all=True, append_images=imgs[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment