I am a total novice to Python and have been testing my skills recently. I found this particular challenge and wanted to give it a shot. I made this code and it functions well, but very slowly. I was looking for feedback on how to optimize in Python, as well as general Python best practices!
Main.py
from PIL import Image
IMGHeight = 2000
IMGWidth = 2000
xmin = -2.0
xmax = 2.0
ymin = -2.0
ymax = 2.0
def Function(z):
return z*z + complex(-0.221, -0.713)
def Pixel(point):
#set up how the complex number will create a pixel
limit = 255
thresh = 2
val = Function(point)
for I in range(1, limit):
if(abs(val) > thresh):
return I
val = Function(val)
return limit
def main():
myImg = Image.new('L', (IMGWidth+1,IMGHeight+1))
for x in range(IMGWidth):
zx = x * (xmax - xmin)/(IMGWidth - 1) + xmin
for y in range(IMGHeight):
zy = y * (ymax - ymin)/(IMGHeight - 1) + ymin
z = complex(zx, zy)
#pixels.append(Pixel(z))
myImg.putpixel((x,y), Pixel(z))
myImg.save('Fractals.png')
if __name__ == "__main__":
main();