Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_spectral_fit_mandelbrot2.py
- import math
- #frame parameters
- 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='''
- #FF0000
- #FF8000
- #FFFF00
- #80FF00
- #00FF00
- #00FF80
- #00FFFF
- #0080FF
- #0000FF
- #8000FF
- #FF00FF
- #FF007F
- '''.strip().split()
- 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(Lr*10):
- 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[(i-1)%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