June 2017
Beginner
352 pages
8h 39m
English
In order to generate a BMP image file, we're going to need some pixel data. We've included a simple module fractal.py which produces pixel values for the iconic Mandelbrot set fractal. We're not going to explain the fractal generation code in detail, still less the math behind it. But the code is simple enough, and it doesn't rely on any Python features we haven't encountered previously:
# fractal.py"""Computing Mandelbrot sets."""import mathdef mandel(real, imag): """The logarithm of number of iterations needed to determine whether a complex point is in the Mandelbrot set. Args: real: The real coordinate imag: The imaginary coordinate Returns: An integer in the range 1-255. """ x = 0 y = 0 for i in range(1, 257): if x*x ...
Read now
Unlock full access