Advertisement
farry

Tkinter Mandelbrot Set

Aug 5th, 2018
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | None | 0 0
  1. from time import time
  2. from tkinter import Tk, Label, PhotoImage
  3. from math import log
  4.  
  5. w = 1000; h = 800
  6. t1 = time()
  7. root = Tk()
  8. label = Label(root)
  9. label.pack()
  10. img = PhotoImage(width=w,height=h)
  11. label.config(image=img)
  12. root.wait_visibility()
  13. xc = -0.6; yc = 0.005; m = 0.65
  14. imax = 100; zmax = 50
  15.  
  16. for y in range(h):
  17.   hexdata = ""
  18.   for x in range(w):
  19.     c = complex(xc + (2 * x - w) / (w * m), -yc - (2 * y - h) / (w * m))
  20.     z = complex(0.0, 0.0)
  21.     for i in range(imax):
  22.       z = z * z + c
  23.       if abs(z) >= zmax: break
  24.     if i >= imax - 1:
  25.       hexdata += "#000000 "
  26.     else:
  27.       zlog = (i - log(log(abs(z)),2)) * 0.7;
  28.       v = log(max(1.0, zlog * 1.5 + 1.0)) * 0.3;
  29.       if v <= 1.0:
  30.         rgb = (v ** 4, v ** 2.5, v)
  31.       else:
  32.         v = max(0.0, 2.0 - v)
  33.         rgb = (v, v ** 1.5, v ** 3)
  34.       hexdata += '#' + ''.join(['%02x' % int(n * 255) for n in rgb]) + ' '
  35.   data = '{ ' + hexdata + ' }'
  36.   img.put(data, to=(0,y))
  37.   root.update()
  38.  
  39. print( "Elapsed time:", '%7.2f' % (time() - t1), "s" )
  40. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement