Created
December 8, 2020 09:54
-
-
Save EllieTheYeen/406802fc839d8b5afd220899048465a4 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, ImageDraw | |
import numpy as np | |
os.chdir(os.path.split(__file__)[0] or '.') | |
gsize = 100, 100 | |
grid = np.random.randint(0, 2, gsize, dtype=np.uint8) | |
isize = 800, 800 | |
i = Image.new('RGB', isize) | |
d = ImageDraw.Draw(i) | |
bw = int(isize[0] / gsize[0]) | |
bh = int(isize[1] / gsize[1]) | |
for x in range(gsize[1]): | |
for y in range(gsize[0]): | |
p = (int(grid[y, x] * 255),) * 3 | |
#d.rectangle((x * 8, y * 8, x * 8 + 7, y * 8 + 7), fill=p) | |
d.rectangle((x * bw, y * bh, x * bw + bw - 1, y * bh + bh - 1), fill=p) | |
i.save('blocks.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment