Advertisement
farry

mandelbrot-cosine

May 13th, 2019
1,428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. from tkinter import Tk, Label, PhotoImage
  4. from math import log, pi
  5. from cmath import cos
  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.9
  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 = complex(0.0, 0.0)
  23.         backgnd = 0
  24.         for i in range(imax):
  25.             z =   c + pi * cos(z)
  26.             if abs(z.imag) >= zmax:
  27.                 backgnd = log(i - log(log(abs(z.imag)),20)) / 3.0
  28.                 break
  29.         v = max(0.0, 1.0 - abs(1.0 - backgnd))
  30.         blue = (v ** 4, v ** 2.5, v)
  31.         sepia = (v, v ** 1.5, v ** 3)
  32.         color = blue if backgnd <=1 else sepia
  33.         hexdata += '#%02X%02X%02X ' % tuple(int(n * 255) for n in color)
  34.     img.put('{' + hexdata + '}', to=(0,y))
  35.     root.update()
  36.  
  37. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement