Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_mandelbrot4.py
- import math
- import os
- #frame parameters
- ww = 600
- hh = 600
- try:
- import tkinter as tk
- except:
- import Tkinter as tk
- root=tk.Tk()
- root.title("Tk 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
- precision = 500
- 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)
- Lr = len(rainbow)
- up = 9.08373867835
- zz = 6.86105967195
- zz = Lr / (up + zz)
- 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(precision + 1):
- a = x*x - y*y #real component of z^2
- b = 2 * x * y #imaginary component of z^2
- x = a + oldX #real component of new z
- y = b + oldY #imaginary component of new z
- if x*x + y*y > 4:
- break
- if i < precision:
- j = int((x**2+y**2)**0.5*100)
- rgb = rainbow[j%Lr]
- canvas.create_oval((col,row,col+1,row+1),outline=rgb)
- else:
- canvas.create_oval((col,row,col+1,row+1),outline='black')
- index = row * ww + col + 1
- # print("{} / {}, {}%".format(index, ww * hh, round(index / ww / hh * 100 * 10) / 10))
- canvas.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement