Mandelbrot Set with Python
Now that I have a little bit of experience with programming and python I’ve been looking around at other people’s projects to see what I can do on my own. I saw some videos online of people making Mandelbrot and Julia sets. I’ve always found natural patterns fascinating so I was immediately interested in making my own. I ended up doing a bit of google research and watching several cool mathematic videos on the topic, that I partially understood, and then came across some pseudocode on the Wikipedia page(https://en.wikipedia.org/wiki/Mandelbrot_set). I learned that you can make your own render using a fairly straight forward while-loop algorithm.
If you don’t know what a Mandelbrot Set is you can watch this videos (https://www.youtube.com/watch?v=NGMRB4O922I) to get a better explanation than what I can give. Basically, though you color a pixel based on how quickly a given value, upon iteration, will go to infinity.
My first major hurdle was figure out how to render the image. I ended up using a module that was explained in Automate the Boring Stuff. After spending some time figure out why the image was rendering black I got a very basic render of the set. The render didn’t have a lot of detail, so then I had to up the resolution and implement a way for the user to move around and zoom into different area to see more interesting results.
I was also at this time playing around with the threshold between the different color values. At first, I was rendering the results in black and white, but then figured out that you could adjust the color weight of the red, green, blue values based on a given threshold to add color. The problem then become that the image was very flat especially in the edges area, which is where you want to see more detail, since that is where the cool spiral patterns are. To compensate for this I wrote a little function that converted the color from linear to logarithmic. Even though this caused the image to come out more flat it add more detail in the midrange values which I could then take into a program like Nuke or Photoshop and color adjust for better results.
Looking back at my code there is several design choices that I would have made differently. For one, I would have encapsulated different actions into individual methods instead of having it all execute in one large block of code. However, the intention of the project was just to explore rendering a Mandelbrot Set and not necessarily focusing on the design of the program. Plus, design concepts was still very new to me. I feel like I have a better handle on it these days though. In the end, I was happy with this project. I got some cool looking renders which always a plus, and got more practice with python. The part I was most happy with was actually the color space conversion between linear and log. I was proud of myself for programming that since the topic of colorspace always seems so confusing.
Link to Mandelbrot Set Repo: https://github.com/zackthomas1/madnelbrotSet