here2share

# Tk_quasicrystals.py

Apr 7th, 2021
421
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Tk_quasicrystals.py
  2.  
  3. from Tkinter import *
  4. from PIL import Image, ImageTk
  5. import math
  6. import random
  7.  
  8. # image size
  9. ww = 640
  10. hh = 640
  11.  
  12. root = Tk()
  13. root.title("Tk Quasicrystals")
  14. root.geometry("%dx%d+0+0"%(ww,hh))
  15. canvas = Canvas(root, width=ww, height=hh)
  16. canvas.grid()
  17.  
  18. img = Image.new("RGB", (ww, hh))
  19. pixels = img.load()
  20.  
  21. while 1:
  22.     f = random.random() * 40.0 + 10 # frequency
  23.     p = random.random() * math.pi # phase
  24.     n = random.randint(10, 20) # of rotations
  25.     print(f,p,n)
  26.     for ky in range(hh):
  27.         y = float(ky) / (hh - 1) * 4 * math.pi - 2 * math.pi
  28.         for kx in range(ww):
  29.             x = float(kx) / (ww - 1) * 4 * math.pi - 2 * math.pi
  30.             z = 0.0
  31.             for i in range(n):
  32.                 r = math.hypot(x, y)
  33.                 a = math.atan2(y, x) + i * math.pi * 2.0 / n
  34.                 z += math.cos(r * math.sin(a) * f + p)
  35.             c = int(round(255 * z / n))
  36.             pixels[kx, ky] = (c, c, c) # grayscale
  37.             canvas.update()
  38.     imgTk = ImageTk.PhotoImage(img)
  39.     canvas.create_image(0, 0, image=imgTk, anchor='nw')
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×