Please follow PEP 8, you ca use tools like pylint to find PEP 8 issues immediately. But for instance:
Function -> function
Pixel -> pixel
There are other small related issues.
Python has docstrings which are ways to document your functions. It isn't exactly clear what
Pixel do at the moment.
You have a comment describing
Pixel. Two things about this comment:
- I don't understand it, what do you mean by "create a pixel"?
- It is not, as of now a docstring, to make it one, use the triple quoted string and put right below the function declaration, so:
#set up how the complex number will create a pixel
"""Set up how the complex number will create a pixel"""
But, again you should probably reword the comment, at the moment the meaning is not so clear, possibly:
"""Calculate the color threshold for a particular pixel"""
I would argue that you should add an additional parameter to
Function is one of the many functions you could pass into the set so allow someone else to change it and add
f as a parameter to
Pixel and pass the function in.
What would I change to optimize the code?*
Instead, I would first switch to PyPy (which uses JIT compilation to make the code, in this case, much faster) and run the program that way, install PyPy, then (this worked for me):
pypy -m pip install Pillow
pypy run it. Here are the time comparisons on my computer:
➜ codereview time pypy julia.py
pypy julia.py 3.10s user 0.07s system 99% cpu 3.198 total
➜ codereview time python julia.py
python julia.py 33.53s user 0.30s system 96% cpu 35.224 total
Just to be clear though, PyPy isn't always the best solution. It's great in this case though because you are repeatedly calling the same two functions over and over again, something that PyPy is generally much better than CPython at doing.
For a lot of, often considered, "slower" languages simply changing the implementation can do wonders.
* Well there are probably other things you can do, but switching the language is sooo easy, and helps with sooo much!