Advertisement
here2share

# Tk_Mandelbrot_basic.py

May 12th, 2022
913
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | None | 0 0
  1. # Tk_Mandelbrot_basic.py
  2.  
  3. from tkinter import Tk, Label, PhotoImage
  4. from math import log, pi
  5. from cmath import cos,sin, exp
  6.  
  7. w, h = 1200, 960
  8. root = Tk()
  9. label = Label(root)
  10. label.pack()
  11. img = PhotoImage(width=w,height=h)
  12. label.config(image=img)
  13. root.wait_visibility()
  14. xc, yc = - 0.35, 0.005
  15. mag = 0.4
  16. imax, zmax = 100, 100
  17.  
  18. for y in range(h):
  19.     hexdata = ""
  20.     for x in range(w):
  21.         c = complex(xc + (2*x - w) / (w*mag), -yc - (2*y - h) / (w*mag))
  22.         z = c
  23.         backgnd = 0
  24.         for i in range(imax):
  25.             try:
  26.                 z = c + z*z
  27.             except:
  28.                 z = complex(0, zmax)
  29.            
  30.             try:
  31.                 if abs(z) >= zmax:
  32.                     backgnd = log(i - log(log(abs(z.imag)),20)) / 3.0
  33.                     break
  34.             except:
  35.                 backgnd = 0
  36.                 break
  37.            
  38.         v = max(0.0, 1.0 - abs(1.0 - backgnd))
  39.         blue = (v ** 4, v ** 2.5, v)
  40.         sepia = (v, v ** 1.5, v ** 3)
  41.         color = blue if backgnd <=1 else sepia
  42.         hexdata += '#%02X%02X%02X ' % tuple(int(n * 255) for n in color)
  43.     img.put('{' + hexdata + '}', to=(0,y))
  44.     root.update()
  45.  
  46. root.mainloop()
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement