Code on github.
Per Wikipedia, the Mandelbrot set is the set of complex numbers for which the a particular function does not diverge from the origin when iterated. The particular function is: fc(z) = z2 + c
The important facts are that the space is the complex plane, and the colour-coding normally seen corresponds to the number of iterations required for the new value of c to be seen to diverge (have an absolute value above 4). My code for checking and colouring was:
def iter_score(re, im):
x = 0
y = 0
iters = -1
while iters < ITERATION_LIMIT and x * x + y * y < 4:
next_x = x * x - y * y + re
y = 2 * x * y + im
x = next_x
iters += 1
grey_val = iter_score
return [grey_val, grey_val, grey_val]
Could have been more inventive on the colouring, or at least switched the rendering to greyscale. As it is, it’s RGB, but only giving greys:
Main Python note was the issue around getting PyPNG installed so I could “import png”. Perhaps nor surprisingly, it matters which environment is active when you pip-install something. Presumably the environment includes an indicator of which packages are installed (perhaps a directory name?). Anyway, installing a package with the conda environment running doesn’t help when you’re trying to use the package in PyCharm with its own venv! Lesson learned.