import tkinter as tk width = 100 height = 100 max_iterations = 30 upperbound = 1000 upperleft = complex(-2, 1.25) downright = complex(1, -1.25) 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 for x in range(0, width): for y in range(0, height): c = complex(x * xfactor + upperleft.real, y * yfactor + upperleft.imag) z = 0 + 0j 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, 0) line = canvas.create_rectangle(x, y, x + 1, y + 1, fill=color, outline="") usingIDLE = 0 if not usingIDLE: root.mainloop()