Advertisement
here2share

# tk_infinite_cavern.py

May 14th, 2023 (edited)
978
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.23 KB | None | 0 0
  1. # tk_infinite_cavern.py
  2.  
  3. import tkinter as tk
  4. import math
  5. import random
  6. from PIL import Image, ImageTk, ImageFilter, ImageGrab
  7. import ctypes
  8.  
  9. ww = 600
  10. hh = 600
  11. cx, cy = ww//2, hh//2
  12.  
  13. root = tk.Tk()
  14. root.geometry("%dx%d+0+0"%(ww,hh))
  15. canvas = tk.Canvas(root, bg='white', width=ww, height=hh)
  16. canvas.pack()
  17.  
  18. radius = 1.5
  19.  
  20. rgb = [i for i in range(0, 256, 5)]
  21. colors = ['#{:02x}{:02x}{:02x}'.format(r,g,b) for r in rgb for g in rgb for b in rgb][40:-40]
  22. random.shuffle(colors)
  23.  
  24. number_of_points = 12
  25. morph_steps = 400
  26.  
  27. points = []
  28. def blob():
  29.     points[:] = []
  30.     for j in range(number_of_points):
  31.         angle = 2 * math.pi * j / number_of_points
  32.         r = radius * random.uniform(0.2, 1)
  33.         a = angle * random.uniform(0.95, 1)
  34.         x = cx + r * math.cos(a)
  35.         y = cy + r * math.sin(a)
  36.         points.append((x, y))
  37.  
  38. # Zoom into the center of the screen
  39. i = 0
  40. scale = 1.02
  41. blur_img = Image.new('RGB', (ww, hh), "white")
  42. blur_img = blur_img.filter(ImageFilter.GaussianBlur(5))
  43. while True:
  44.     canvas.scale('all', cx, cy, scale, scale)
  45.     if not int(i) % 80:
  46.         blob()
  47.         color = colors.pop(0)
  48.         canvas.create_polygon(points, smooth=True, fill=color, outline='')
  49.         colors.insert(-(10-int(i%10)), color)
  50.     i += scale
  51.     i %= 999999999
  52.     canvas.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement