Advertisement
farry

white-cuts-on-black-forever.py

Aug 6th, 2020
2,470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.28 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import tkinter as tk
  4. import numpy as np
  5. from PIL import Image, ImageDraw, ImageChops, ImageOps, ImageFilter, ImageEnhance
  6. from PIL import ImageTk
  7. import time
  8.  
  9. size=800
  10. cuts, reps = 20, 8
  11.  
  12. blankimg = Image.new('L', (size, size), color=0)
  13. root = tk.Tk()
  14. label = tk.Label(root)
  15. label.pack()
  16. img = blankimg.copy()
  17.  
  18. cut, step = 0, 0
  19. while True:
  20.     if step == 0:
  21.         cut = cut + 1
  22.         rand = np.random.RandomState(cut + 100)
  23.         anglerotate = np.exp(rand.uniform(0, np.pi) * 2j)
  24.         angleshift = np.array([anglerotate * 1j]).view(float)
  25.         offset = rand.uniform(0.05, 0.4)
  26.         randomwalk = np.cumsum(rand.uniform(-0.0015, 0.0015, 2*size))
  27.         smoothline = np.convolve(randomwalk,np.ones(10)/10,'same')
  28.         centeredline = (smoothline - smoothline[len(smoothline) // 2])
  29.         offsetline = centeredline + offset
  30.         complexline = offsetline * 1j + np.linspace(-1, 1, len(offsetline))
  31.         maskbox =  [1 -2j, -1 -2j]
  32.         rotatedline = np.hstack((maskbox, complexline)) * anglerotate
  33.         linelist = list(((rotatedline.view(float) + 0.5) * size).astype(int))
  34.         imgline = blankimg.copy()
  35.         ImageDraw.Draw(imgline).line(linelist, fill=255, width=2)
  36.         mask1 = imgline.copy()
  37.         ImageDraw.Draw(mask1).polygon(linelist, fill=255)
  38.         mask2 = ImageChops.lighter(imgline, ImageChops.invert(mask1))
  39.  
  40.         img = ImageChops.lighter(img, imgline)
  41.         split1 = ImageChops.darker(img, mask1)
  42.         split2 = ImageChops.darker(img, mask2)
  43.        
  44.         splitsize = rand.randint(10, 20)
  45.         lineblur = imgline.filter(ImageFilter.GaussianBlur(radius=10))
  46.  
  47.     shift = 2 + splitsize * step / 10
  48.     splitstep = (angleshift * shift).astype(int)
  49.  
  50.     shifted1 =  ImageChops.offset(split1, *-splitstep)
  51.     shifted2 =  ImageChops.offset(split2, *splitstep)
  52.     img = ImageChops.lighter(shifted1, shifted2)
  53.    
  54.     flash = ImageEnhance.Contrast(lineblur).enhance(10 - 2 * step)
  55.     flashimg = ImageChops.lighter(img, flash)
  56.     cropimg = ImageOps.crop(flashimg, border=size*.05)
  57.    
  58.     tkimg = ImageTk.PhotoImage(cropimg)
  59.     label.config(image=tkimg)
  60.     step = (step + 1) % 10
  61.  
  62.     # just crash out when window closed, terrible I know
  63.     root.update()
  64.     time.sleep(0.04)
  65.  
  66.  
  67.  
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement