Skip to content

Instantly share code, notes, and snippets.

@arvganesh
Last active September 24, 2016 07:58
Show Gist options
  • Save arvganesh/ba94bb32cb2824578e0fa8d7715a4cde to your computer and use it in GitHub Desktop.
Save arvganesh/ba94bb32cb2824578e0fa8d7715a4cde to your computer and use it in GitHub Desktop.
from Tkinter import *
import Tkinter
def iterate(x, y, iterationNum): # I am not sure if I am doing this part correctly.
z = 0
coord = complex(x, y)
while iterationNum:
z = z * z + coord
if z ** 2 > 4:
return False
return True
def pixel(image,x,y,r,g,b):
"""Place pixel at pos=(x,y) on image, with color=(r,g,b)"""
image.put("#%02x%02x%02x" % (r,g,b), (y, x))
def mandelbrot():
WIDTH = 640; HEIGHT = 480
TopLeftX = -200; BottomRightX = 200
TopLeftY = 200; BottomRightY = -200
Increment = 5
maxIt = 100
w = BottomRightX - TopLeftX
h = TopLeftY - BottomRightY
canvas = Canvas(window, width = WIDTH, height = HEIGHT, bg = "#ffffff")
img = PhotoImage(width = WIDTH, height = HEIGHT)
canvas.create_image((0, 0), image = img, state = "normal", anchor = Tkinter.NW)
for x in xrange(TopLeftX, BottomRightX, -5):
for y in xrange(TopLeftY, BottomRightY, -5):
xnum = x / 100.0
ynum = y / 100.0
if iterate(xnum, ynum, maxIt):
pixel(img, xnum, ynum, 255, 0, 0)
else:
pixel(img, xnum, ynum, 255, 255, 255)
canvas.pack()
mainloop()
mandelbrot()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment