Hypnose-Spirale
Verfasst: Donnerstag 15. September 2005, 16:05
Hi!
Mal wieder ein ganz wichtiges und brauchbares Snippet
WARNUNG: Nicht zu lange zusehen, kann zu Verblödung führen (Ihr wollt doch nicht so werden wie ich, oder?)
PS: Das ist nicht wirklich von mir, nur eine (fast 1:1) Übersetzung eines TCL Scripts.
Gruß, hypnotischer mawe
Mal wieder ein ganz wichtiges und brauchbares Snippet

WARNUNG: Nicht zu lange zusehen, kann zu Verblödung führen (Ihr wollt doch nicht so werden wie ich, oder?)

Code: Alles auswählen
from Tkinter import *
import math
import time
def create_spiral(x,y):
res = [(x,y)]
while len(res) <= 500:
r = math.hypot(x,y) + 0.4
a = math.atan2(y,x) + 0.2
x = r * math.cos(a)
y = r * math.sin(a)
res.append((x,y))
c.create_line(res, width=3, tags="line")
def rotate(x0,y0,d):
coords = []
old = c.coords("line")
for i in range(0,len(old),2):
x,y = old[i], old[i+1]
r = math.hypot(y-y0, x-x0)
a = math.atan2(y-y0, x-x0) + d
x = x0 + r*math.cos(a)
y = y0 + r*math.sin(a)
coords.append((x,y))
c.delete("line")
c.create_line(coords, width=3, tags="line")
root = Tk()
c = Canvas(width=400, height=400)
c.pack()
create_spiral(0,0)
c.config(scrollregion=c.bbox(ALL))
while 1:
rotate(0,0,0.1)
root.update()
time.sleep(0.01)
root.mainloop()
Gruß, hypnotischer mawe