Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/owainkenwayucl/fractals
Python (some Julia!) tools for generating fractals
https://github.com/owainkenwayucl/fractals
julia-sets julialang mandelbrot numpy python3
Last synced: 12 days ago
JSON representation
Python (some Julia!) tools for generating fractals
- Host: GitHub
- URL: https://github.com/owainkenwayucl/fractals
- Owner: owainkenwayucl
- License: mit
- Created: 2018-09-26T15:43:25.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-07-20T20:58:26.000Z (over 1 year ago)
- Last Synced: 2024-11-30T07:25:02.712Z (2 months ago)
- Topics: julia-sets, julialang, mandelbrot, numpy, python3
- Language: Python
- Homepage:
- Size: 414 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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](https://github.com/owainkenwayucl/mandel), [OpenWatcom Fortran 77 for DOS](https://github.com/owainkenwayucl/mandel77), [FreeBASIC](https://github.com/owainkenwayucl/mandbas)) 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 fractalsfractals.show_image(fractals.generate_fractal(600,400, fractals.mandel, max_iter=50))
```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).
![Output of mandelbrot.py](img/mandel.png)
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).
```python
import fractals# Generate julia sets as per https://en.wikipedia.org/wiki/Julia_set#Examples_of_Julia_sets
n = 2
c = [0.279, 0.400, 0.484, 0.544, 0.590, 0.626]
for i in c:
j = fractals.generate_julia(i,n)
fractals.show_image(fractals.generate_fractal(600,600, j, max_iter=50, xmin=-2.0, xmax=2.0, ymin=-2.0, ymax=2.0))
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](img/julia1.png)
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](img/mandel2.png)
You can of course then save the plot from Matplotlib.