Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_quasicrystals.py
- from Tkinter import *
- from PIL import Image, ImageTk
- import math
- import random
- # image size
- ww = 640
- hh = 640
- root = Tk()
- root.title("Tk Quasicrystals")
- root.geometry("%dx%d+0+0"%(ww,hh))
- canvas = Canvas(root, width=ww, height=hh)
- canvas.grid()
- img = Image.new("RGB", (ww, hh))
- pixels = img.load()
- while 1:
- f = random.random() * 40.0 + 10 # frequency
- p = random.random() * math.pi # phase
- n = random.randint(10, 20) # of rotations
- print(f,p,n)
- for ky in range(hh):
- y = float(ky) / (hh - 1) * 4 * math.pi - 2 * math.pi
- for kx in range(ww):
- x = float(kx) / (ww - 1) * 4 * math.pi - 2 * math.pi
- z = 0.0
- for i in range(n):
- r = math.hypot(x, y)
- a = math.atan2(y, x) + i * math.pi * 2.0 / n
- z += math.cos(r * math.sin(a) * f + p)
- c = int(round(255 * z / n))
- pixels[kx, ky] = (c, c, c) # grayscale
- canvas.update()
- imgTk = ImageTk.PhotoImage(img)
- canvas.create_image(0, 0, image=imgTk, anchor='nw')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement