Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_fibonacci_sphere.py
- from Tkinter import *
- import math
- import random
- import time
- root = Tk()
- c_width = 600
- c_height = 600
- canvas = Canvas(root, width=c_width, height=c_height, bg='white')
- canvas.pack()
- def fibonacci_sphere(samples=1):
- points = []
- offset = 2./samples
- increment = math.pi * (3. - math.sqrt(5.));
- for i in range(samples):
- y = ((i * offset) - 1) + (offset / 2);
- r = math.sqrt(1 - pow(y,2))
- phi = ((i + 1.) % samples) * increment
- x = math.cos(phi) * r
- z = math.sin(phi) * r
- points.append([x,y,z])
- points.sort(key=lambda z:z[-1])
- return points
- wait = 0
- while 1:
- if not wait:
- points = random.randint(200,500)
- for x,y,z in fibonacci_sphere(points):
- x,y = [int(r*250+300) for r in [x,y]]
- z = int((z+1)*50)/20
- color = '#%02x%02x%02x' % (180, 210-z*12, 180)
- canvas.create_oval(x, y, x+z+4, y+z+4, fill=color, outline=color)
- wait = time.time()+2
- if wait < time.time():
- canvas.update()
- canvas.delete('all')
- wait = 0
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement