项目作者: owainkenwayucl

项目描述 :
Python tools for generating fractals
高级语言: Python
项目地址: git://github.com/owainkenwayucl/Fractals.git
创建时间: 2018-09-26T15:43:25Z
项目社区:https://github.com/owainkenwayucl/Fractals

开源协议:MIT License

下载


Fractals

Generic Python code for generating and exploring fractals

I have a lot of repos on Github for generating Mandelbrot sets (e.g. various languages, OpenWatcom Fortran 77 for DOS, FreeBASIC) but those implementations have very rigidly stuck to a fairly inflexible way of doing things, don’t use built in complex types etc. The code in this repository for Python is designed to be a lot more flexible (but probably a lot slower) to test out some concepts for doing things.

Goals

  • generic to do more than Mandelbrot, e.g. Julia sets [done]
  • use complex types [done]
  • use numpy where possible [ongoing]
  • graphical [done] and image output [done]
  • parallelisation

    Examples

    If you look in mandelbrot.py you will see a fairly normal Mandelbrot example.

    ```python
    import fractals

fractals.show_image(fractals.generate_fractal(600,400, fractals.mandel, max_iter=50))

  1. This example illustrates where I am trying to go - you generically show an image based on the output of a procedure that generates a fractal image of a given size given a function (in this case the one for the Mandelbrot set) and a number of iterations (optional).
  2. ![Output of mandelbrot.py](img/mandel.png)
  3. If you look in `julia.py` you can see an example which generates and displays one after another the example Julia sets shown on [Wikipedia](https://en.wikipedia.org/wiki/Julia_set#Examples_of_Julia_sets).
  4. ```python
  5. import fractals
  6. # Generate julia sets as per https://en.wikipedia.org/wiki/Julia_set#Examples_of_Julia_sets
  7. n = 2
  8. c = [0.279, 0.400, 0.484, 0.544, 0.590, 0.626]
  9. for i in c:
  10. j = fractals.generate_julia(i,n)
  11. fractals.show_image(fractals.generate_fractal(600,600, j, max_iter=50, xmin=-2.0, xmax=2.0, ymin=-2.0, ymax=2.0))
  12. n += 1

Here we can see an example where in order to allow arbitrary values in Julia functions, I have implemented a generic function fractals.julia and then written fractals.generate_julia which takes values of c and n and generates and returns an anonymous function based on fractals.julia which is based on those values so that it may be safely passed to fractals.generate_fractal.

First output of julia.py

The procedure fractals.show_image uses tkinter to display the image. There is also a procedure fractals.show_image_matplotlib which uses Matplotlib to display the image. The examples mandelbrot-mpl.py and julia-mpl.py use this method.

Matplotlib screenshot

You can of course then save the plot from Matplotlib.