Advertisement
Guest User

Gray&White

a guest
May 15th, 2023
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.48 KB | Source Code | 0 0
  1. import random
  2. from PIL import Image, ImageDraw, ImageFilter
  3.  
  4.  
  5. def bbox(x: int, y: int, d: int = 12) -> list[tuple[int, int, int, int]]:
  6.     dd = d * 2
  7.     return [
  8.         (x - d, y - d, x, y),
  9.         (x, y, x + d, y - d),
  10.         (x, y, x + d, y + d),
  11.         (x, y, x - d, y + d),
  12.  
  13.         (x - d, y - d, x + d, y - d),
  14.         (x + d, y - d, x + d, y + d),
  15.         (x - d, y + d, x + d, y + d),
  16.         (x - d, y - d, x - d, y + d),
  17.  
  18.         (x, y + dd, x - d, y + d),
  19.         (x + d, y - d, x + dd, y),
  20.         (x + dd, y, x + d, y + d),
  21.         (x + d, y + d, x, y + dd),
  22.  
  23.         (x, y + dd, x - d, y + d),
  24.         (x - d, y + d, x - dd, y),
  25.         (x - dd, y, x - d, y - d),
  26.         (x - d, y - d, x, y - dd),
  27.     ]
  28.  
  29.  
  30. def gray() -> Image.Image:
  31.     size = 612
  32.     chuncks = 8 # 8x8
  33.     image = Image.new("RGB", (size, size), color=(73, 73, 73))
  34.  
  35.     draw = ImageDraw.Draw(image)
  36.  
  37.     rx = size // chuncks
  38.     x = rx // 2
  39.     y = rx // 2
  40.     d = rx // 6
  41.  
  42.     fill = (255, 255, 255)
  43.     width = 2
  44.  
  45.     for dy in range(chuncks):
  46.         for dx in range(chuncks):
  47.             dpos = (x + rx * dx, y + rx * dy)
  48.             bbx = bbox(*dpos, d=d)
  49.             for pos in random.sample(bbx, k=random.randrange(4, 8)):
  50.                 draw.line(pos, fill=fill, width=width)
  51.  
  52.     image = image.filter(ImageFilter.ModeFilter(3))
  53.     image = image.filter(ImageFilter.BoxBlur(0.05))
  54.  
  55.     return image
  56.  
  57.  
  58. if __name__ == "__main__":
  59.     gray().save("gray.png")
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement