• February 27, 2021, 10:19:36 PM

Login with username, password and session length

Author Topic:  A Mandelbrot script  (Read 527 times)

0 Members and 1 Guest are viewing this topic.

Online GBy

  • Fractal Fanatic
  • ***
  • Posts: 30
A Mandelbrot script
« on: June 02, 2020, 08:58:03 PM »
    Hi,

I have been working on a small python program (rather, a long script) to generate images for different Mandelbrot sets - for the moment:
  • the classical z → z² + c
  • Mandelbrot sets for rational functions with a higher monome degree ≥ 2 – ie with a super-attractive fixed point at infinity

I know that there are a lot of more user-friendly / optimized / deep-zooming programs out there. It suffers from some obvious flaws (speed, ...) but I am pleased with some image it produces.
Following a discussion on this site it seems some people could be interested by the program / source code, so here we go.

This program itself is written in python (python 2.7, I should have switched to python3 some time ago…) and uses the following dependencies: numpy, matplotlib, Pillow.
Here I share the part for the classical Mandelbrot (I need some more time to tidy the code for rational maps, which I will do later on if some manage to run this code and are interested for more)
It is composed of 3 files:
fractal.py Main low-level part, defining 4 classes
  • Color_tools for color operation in CIE color space (shading, color gradient, …)
  • Fractal_colormap maps floats to colors
  • Fractal_plotter plots a fractal object
  • Fractal abstract base class encapsulating a fractal object, to be subclassed
classical_mandelbrot.py defines the class Classical_mandelbrot (z → z² + c) – subclass of Fractal
run_mandelbrot.py runs calculations to produce 4 plots (intended as working example). The first one is only ‘draft mode’ I use it for exploring, for the 3 other I will put below the output of the program.

To run the program you need to have installed python 2.7, numpy, Pillow and matplotlib. If you do not have I personally use the Anaconda distribution which ships all these (and a lot more...), opensource and available for windows, mac, linux. https://www.anaconda.com/products/individual

Then simply put the 3 files in the same directory and launch  run_mandelbrot.py from your preferred development environment – I use Spyder) -

  """=====================================================================
    Run the script to generate 1 of 4 fractal images
    User-input needed : *choice* and the target *directory*
===================================================================="""

License:
Feel free to ignore, use or include in your own source code. However if you enjoy or include it I would be happy to know!

Linkback: https://fractalforums.org/programming/11/a-mandelbrot-script/3546/
« Last Edit: June 02, 2020, 09:18:17 PM by GBy »

Online GBy

  • Fractal Fanatic
  • ***
  • Posts: 30
Re: A Mandelbrot script
« Reply #1 on: June 02, 2020, 09:01:23 PM »
I here below post the 3 example outputs image, direct output if you run the program at resolution 1600 x 1600, simply downscaled to 1000 x 1000

1) billiard game (choice = 4)
« Last Edit: June 02, 2020, 09:14:21 PM by GBy »

Online GBy

  • Fractal Fanatic
  • ***
  • Posts: 30
Re: A Mandelbrot script
« Reply #2 on: June 02, 2020, 09:02:52 PM »
2) medaillon (choice = 2)
this one uses 'longdouble' so could be machine-dependent
« Last Edit: June 02, 2020, 09:14:54 PM by GBy »

Online GBy

  • Fractal Fanatic
  • ***
  • Posts: 30
Re: A Mandelbrot script
« Reply #3 on: June 02, 2020, 09:04:54 PM »
3) Emerauld shield (choice = 3)
This one also uses longdoubles and is suite longish to run due to the density of the scene
« Last Edit: June 02, 2020, 09:15:30 PM by GBy »

Offline blob

  • Fractal Phenom
  • ****
  • Posts: 49
Re: A Mandelbrot script
« Reply #4 on: June 02, 2020, 11:23:16 PM »
Script failed on windows and I thought I had outdated dependencies but it wasn't this (updating them certainly wasn't a bad thing however).

So https://github.com/quantumlib/Cirq/issues/1511 came to the rescue and I was able to render draft and billiard so far. Medallion is currently running and I'll see if it completes, I've got an old computer so it's a bit slow.

Nice, thanks!

Offline blob

  • Fractal Phenom
  • ****
  • Posts: 49
Re: A Mandelbrot script
« Reply #5 on: June 02, 2020, 11:54:28 PM »
Medaillon finished rendering but the minibrot isn't rendered as nicely as yours. I've no clue why obviously.


Offline claude

  • 3f
  • ******
  • Posts: 1784
    • mathr.co.uk
Re: A Mandelbrot script
« Reply #6 on: June 02, 2020, 11:58:12 PM »
Guess: the fix in the page you linked to replaces `long double` (traditionally 80bit on x87, though the C standards make no guarantees about it) with `double` which loses precision.

Online GBy

  • Fractal Fanatic
  • ***
  • Posts: 30
Re: A Mandelbrot script
« Reply #7 on: June 03, 2020, 07:14:25 AM »
Claude explanation is right but you may have a workaround.

On my (Linux) machine:
Code: [Select]
> print np.finfo(np.longdouble)Machine parameters for float128
---------------------------------------------------------------
precision= 18   resolution= 1e-18
machep=   -63   eps=        1.08420217249e-19
negep =   -64   epsneg=     5.42101086243e-20
minexp=-16382   tiny=       3.36210314311e-4932
maxexp= 16384   max=        1.18973149536e+4932
nexp  =    15   min=        -max
---------------------------------------------------------------

I guess under windows it falls back to float64. See also :
https://stackoverflow.com/questions/25481058/how-do-i-use-the-numpy-longdouble-dtype

Still to be checked if this example  really requires 80-bits precision at 1600x1600 pixels. Simply set the 2 epsilon at 1e.15 in the code :
Code: [Select]
eps_pixel = 1e-15...
Code: [Select]
mandelbrot.newton_cycles(file_prefix="newton", subset=stationnary,
                             max_newton=16, max_cycle=40000, eps_cv=1.e-15,
                             start_file="teleportation",
                             r_candidate_file="r_candidate",
                             known_order=known_order)

And hopefully this could give a better result.
Note it may explain also why it was very slow...

Edit: I will do the test myself later today I thought it was ok but I somehow wrote to fast... PS you have to delete at least the 'newton' data files otherwise the program will simply reload them not recompute.
« Last Edit: June 03, 2020, 08:05:07 AM by GBy »

Offline blob

  • Fractal Phenom
  • ****
  • Posts: 49
Re: A Mandelbrot script
« Reply #8 on: June 03, 2020, 08:14:51 AM »
Thanks, I'll try this out later.

From what I've read it seems the problem is that the Microsoft compiler used to build the most easily available python and packages binaries has no support whatsoever for high precision.

 I  found out I had a working gcc-compiled python 2.7 on my machine (inside an msys instalation) and I am going to install the necessary packages from the Msys2 repo hoping the script will work as for you guys on Linux.
« Last Edit: June 03, 2020, 08:45:53 AM by blob »

Online GBy

  • Fractal Fanatic
  • ***
  • Posts: 30
Re: A Mandelbrot script
« Reply #9 on: June 03, 2020, 08:08:25 PM »
    Hi Blob,

So I confirm, you should get a correct result for the 'medaillon' case with
Code: [Select]
complex_type = np.complex128
Code: [Select]
eps_pixel =  dx / float(nx)
Code: [Select]
eps_cv=1.e-15
For the 'shield' case probably need throwing extra-precision...

Offline blob

  • Fractal Phenom
  • ****
  • Posts: 49
Re: A Mandelbrot script
« Reply #10 on: June 04, 2020, 08:33:19 PM »
Hi, with the modifications you suggested "medaillon" renders as good as yours, thanks.

Offline shapeweaver

  • Fractal Friend
  • **
  • Posts: 17
Re: A Mandelbrot script
« Reply #11 on: June 05, 2020, 04:58:23 AM »
I don't recommend worrying about high precision until your fractal program has significant features available that other programs out there don't.

At that point, you will have three choices: incorporate high precision into your program, add your feature to a program like KF, or ask for the writer(s) to add it.

Online GBy

  • Fractal Fanatic
  • ***
  • Posts: 30
Re: A Mandelbrot script
« Reply #12 on: June 14, 2020, 05:09:20 PM »
I have added support for 2 Mandelbrot-like sets :
- power tower
- Nova fractals with f(z) = z**p -1

I pushed the code under Github :
https://github.com/GBillotey/Fractal-shades

I will push a small gallery below, the scripts to generate the image is shared under the Github repository.

Online GBy

  • Fractal Fanatic
  • ***
  • Posts: 30
Re: A Mandelbrot script
« Reply #13 on: June 14, 2020, 05:10:04 PM »
Nova 6 :

Online GBy

  • Fractal Fanatic
  • ***
  • Posts: 30
Re: A Mandelbrot script
« Reply #14 on: June 14, 2020, 05:11:36 PM »
Power tower :


lamp
Render all presets from fqs script

Started by 3DickUlus on Code Snippets (fragments)

3 Replies
213 Views
Last post June 15, 2019, 09:32:33 AM
by Sabine62
xx
can somebody convert this to a color smoothing/whatever script

Started by DJ Saint-Hubert on Programming

1 Replies
418 Views
Last post February 09, 2018, 06:37:24 AM
by WAUthethird
xx
Script for stacking jittered images

Started by gerrit on Kalles Fraktaler

4 Replies
401 Views
Last post March 07, 2018, 07:41:35 PM
by gerrit
xx
user interface not redrawn while FQS script is running

Started by claude on Fragmentarium

10 Replies
515 Views
Last post February 25, 2019, 11:54:20 PM
by 3DickUlus
smiley
Skyship generated in StructureSynth - script included

Started by kronpano on StructureSynth & BrowserSynth

0 Replies
124 Views
Last post August 06, 2020, 10:45:05 PM
by kronpano