Grafische Ausgabe einer Mandelbrotmenge.
1 import time
2 import Tkinter as tk
3
4 SIZE = 200
5 LEFT = -2
6 RIGHT = 0.5
7 TOP = 1.25
8 BOTTOM = -1.25
9 ITERATIONS = 20
10
11 root = tk.Tk()
12 can = tk.Canvas(width=250,height=200)
13 can.pack()
14
15 UPDATE_TIME = 0.2
16 start_time = time.time()
17 next_update = start_time + UPDATE_TIME
18 for y in range(SIZE):
19 for x in range(SIZE):
20 z = complex(0,0)
21 c = complex(LEFT + x * (RIGHT-LEFT)/SIZE, TOP + y * (BOTTOM-TOP)/SIZE)
22 for count in range(ITERATIONS):
23 if abs(z) <= 2.0:
24 z = z * z + c
25 else:
26 break
27 if count <= 5:
28 can.create_text(x,y,fill='grey',text='.')
29 elif count<=10:
30 can.create_text(x,y,fill='green',text='.')
31 elif count<=15:
32 can.create_text(x,y,fill='blue',text='.')
33 else:
34 can.create_text(x,y,fill='black',text='.')
35 if time.time() > next_update:
36 next_update = time.time() + UPDATE_TIME
37 root.update()
38
39 root.mainloop()
Entnommen von Mandelbrotmenge mit Tkinter