Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- from mpmath import mp
- import numpy as np
- from PIL import Image
- size = 256
- prec = size ** 2 // 4
- mp.dps = prec * 16 // 10 + 2
- intpi = int(mp.pi * 16 ** (prec - 1))
- tplate = '{{:0{}b}}'.format(size ** 2)
- binpi = np.array([tplate.format(intpi)])
- binarray = binpi.view("U1").astype(np.int8)
- greyval = (binarray * np.int8(255)).reshape(size, size)
- img = Image.fromarray(greyval, mode="L")
- img = img.resize((size * 2, size * 2))
- img.show()
- img.save("pi-square.png")
- binrand = np.random.randint(2, size=size**2, dtype=np.int8)
- greyrand = (binrand * np.int8(255)).reshape(size, size)
- imgrand = Image.fromarray(greyrand, mode="L")
- imgrand = imgrand.resize((size * 2, size * 2))
- imgrand.show()
- imgrand.save("rand-square.png")
Advertisement
Add Comment
Please, Sign In to add comment