-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmandelbrot_zoom.py
67 lines (52 loc) · 1.24 KB
/
mandelbrot_zoom.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import tkinter as tk
import cmath as c
import colorsys as csys
from numba import autojit
# mandelbrot_zoom.py
def html_color(color):
ans = list(map(lambda c: str(hex(int(c)))[2:],color))
for i in range(len(ans)):
if len(ans[i]) == 1:
ans[i] = "0"+ans[i]
return(ans)
size = 1
iter = 200
loc = (0,0)
magnify = 0
i = 0
zoom = 10**magnify
def give_point(event):
global loc, magnify, zoom, iter
x, y = event.x, event.y
x = (((x/(100*size))-2)/zoom)+loc[0]
y = (((y/(100*size))-2)/zoom)+loc[1]
print(x," ",y)
loc = (x,y)
magnify += 1
zoom = 10**magnify
iter += 0
load()
def point(A,B):
z = 0
a = (((A/(100*size))-2)/zoom)+loc[0]
b = (((B/(100*size))-2)/zoom)+loc[1]
for k in range(iter):
if c.polar(z)[0] > 2:
return(k)
z = z*z + (a+b*1j)
return(iter)
def load():
for a in range(int(size*400)):
for b in range(int(size*400)):
value = point(a,b)
color = csys.hls_to_rgb(value/iter,100,1)
color = "#"+"".join(html_color(color))
if value == iter:
color = "black"
can.create_line(a,b,a+1,b,fill=color)
root = tk.Tk()
can = tk.Canvas(root,width=size*400,height=size*400)
can.pack()
load()
can.bind("<Button 1>",give_point)
root.mainloop()