Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_Mandelbrot_basic.py
- from tkinter import Tk, Label, PhotoImage
- from math import log, pi
- from cmath import cos,sin, exp
- w, h = 1200, 960
- root = Tk()
- label = Label(root)
- label.pack()
- img = PhotoImage(width=w,height=h)
- label.config(image=img)
- root.wait_visibility()
- xc, yc = - 0.35, 0.005
- mag = 0.4
- imax, zmax = 100, 100
- for y in range(h):
- hexdata = ""
- for x in range(w):
- c = complex(xc + (2*x - w) / (w*mag), -yc - (2*y - h) / (w*mag))
- z = c
- backgnd = 0
- for i in range(imax):
- try:
- z = c + z*z
- except:
- z = complex(0, zmax)
- try:
- if abs(z) >= zmax:
- backgnd = log(i - log(log(abs(z.imag)),20)) / 3.0
- break
- except:
- backgnd = 0
- break
- v = max(0.0, 1.0 - abs(1.0 - backgnd))
- blue = (v ** 4, v ** 2.5, v)
- sepia = (v, v ** 1.5, v ** 3)
- color = blue if backgnd <=1 else sepia
- hexdata += '#%02X%02X%02X ' % tuple(int(n * 255) for n in color)
- img.put('{' + hexdata + '}', to=(0,y))
- root.update()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement