Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_spectral_fit_mandelbrot.py
- import math
- ww = 600
- hh = 600
- try:
- import tkinter as tk
- except:
- import Tkinter as tk
- root=tk.Tk()
- root.title("Tk Spectral Fit Mandelbrot")
- xc=ww/2
- yc=hh/2
- canvas=tk.Canvas(root,width=ww,height=hh)
- canvas.pack(fill="both",expand=True)
- x = -0.65
- y = 0
- xRange = 3.4
- aspectRatio = 4/3
- yRange = xRange / aspectRatio
- minX = x - xRange / 2
- maxX = x + xRange / 2
- minY = y - yRange / 2
- maxY = y + yRange / 2
- def rgb2hex(rgb):
- r,g,b = rgb
- return "#{:02x}{:02x}{:02x}".format(r,g,b)
- rainbow=[]
- def z(r,g,b):
- rainbow.append(rgb2hex((r,g,b)))
- r,g,b=255,0,0
- for g in range(256):
- z(r,g,b)
- for r in range(254, -1, -1):
- z(r,g,b)
- for b in range(256):
- z(r,g,b)
- for g in range(254, -1, -1):
- z(r,g,b)
- for r in range(256):
- z(r,g,b)
- for b in range(254, -1, -1):
- z(r,g,b)
- for z in range(3):
- rainbow=rainbow[::2]
- Lr = len(rainbow)
- for row in range(hh):
- for col in range(ww):
- x = minX + col * xRange / ww
- y = maxY - row * yRange / hh
- oldX = x
- oldY = y
- for i in range(100):
- a = x*x - y*y #real component of z^2
- b = 2 * x * y #imaginary component of z^2
- if (a*a + b*b)**0.5 > Lr:
- break
- x = a + oldX #real component of new z
- y = b + oldY #imaginary component of new z
- i = 0
- if i:
- rgb = rainbow[int((x*x + y*y)**0.5)%Lr]
- else:
- rgb = 'black'
- canvas.create_oval((col,row,col+1,row+1),outline=rgb)
- canvas.update()
Add Comment
Please, Sign In to add comment