import tkinter as tk width = 200 height = 200 max_iterations = 30 upperbound = 1000 upperleft = complex(-2, 2) downright = complex(2, -2) root = tk.Tk() canvas = tk.Canvas(root, width=width, height=height) canvas.pack() xfactor = (downright.real - upperleft.real) / width yfactor = (downright.imag - upperleft.imag) / height # c = complex(-0.1, 0.1) # c = complex(-0.12375, 0.56508) # c = complex(-0.12, 0.74) # c = complex(-0.11, 0.6557) # c = complex(0, 1) c=complex(0,0) for x in range(0, width): for y in range(0, height): z = complex(x * xfactor + upperleft.real, y * yfactor + upperleft.imag) iter = 0 while iter < max_iterations and abs(z) < upperbound: z = z ** 2 + c iter = iter+1 if iter>= max_iterations: line = canvas.create_rectangle(x, y, x + 1, y + 1, fill="black", outline="") else: color = "#%02x%02x%02x" % ((int)(iter* 256.0 / max_iterations), 0, 125) line = canvas.create_rectangle(x, y, x + 1, y + 1, fill=color, outline="") usingIDLE = 0 if not usingIDLE: root.mainloop()