here2share

# Tk_spectral_fit_mandelbrot2.py

Jan 2nd, 2021 (edited)
527
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.24 KB | None | 0 0
  1. # Tk_spectral_fit_mandelbrot2.py
  2.  
  3. import math
  4.  
  5. #frame parameters
  6. ww = 600
  7. hh = 600
  8.  
  9. try:
  10.     import tkinter as tk
  11. except:
  12.     import Tkinter as tk
  13.  
  14. root=tk.Tk()
  15. root.title("Tk Spectral Fit Mandelbrot")
  16.  
  17. xc=ww/2
  18. yc=hh/2
  19.  
  20. canvas=tk.Canvas(root,width=ww,height=hh)
  21. canvas.pack(fill="both",expand=True)
  22.  
  23. x = -0.65
  24. y = 0
  25. xRange = 3.4
  26. aspectRatio = 4/3
  27.  
  28. yRange = xRange / aspectRatio
  29. minX = x - xRange / 2
  30. maxX = x + xRange / 2
  31. minY = y - yRange / 2
  32. maxY = y + yRange / 2
  33.  
  34. def rgb2hex(rgb):
  35.     r,g,b = rgb
  36.     return "#{:02x}{:02x}{:02x}".format(r,g,b)
  37.  
  38. rainbow='''
  39. #FF0000
  40. #FF8000
  41. #FFFF00
  42. #80FF00
  43. #00FF00
  44. #00FF80
  45. #00FFFF
  46. #0080FF
  47. #0000FF
  48. #8000FF
  49. #FF00FF
  50. #FF007F
  51. '''.strip().split()
  52.  
  53. Lr = len(rainbow)
  54.  
  55. for row in range(hh):
  56.     for col in range(ww):
  57.         x = minX + col * xRange / ww
  58.         y = maxY - row * yRange / hh
  59.         oldX = x
  60.         oldY = y
  61.         for i in range(Lr*10):
  62.             a = x*x - y*y #real component of z^2
  63.             b = 2 * x * y  #imaginary component of z^2
  64.             if (a*a + b*b)**0.5 > Lr:
  65.                 break
  66.             x = a + oldX #real component of new z
  67.             y = b + oldY #imaginary component of new z
  68.             i = 0
  69.         if i:
  70.             rgb = rainbow[(i-1)%Lr]
  71.         else:
  72.             rgb = 'black'
  73.         canvas.create_oval((col,row,col+1,row+1),outline=rgb)
  74.  
  75.     canvas.update()
Add Comment
Please, Sign In to add comment