Products > Programming

Generating Beautiful Fractals

(1/4) > >>

Omega Glory:
Because of the chip shortage, I decided to take a break from hardware projects and experiment more with software. I've created a program to generate plots of the Mandelbrot and Julia sets which turned out quite nicely. The actual set calculation is done in C for speed and access to multithreading, where as the actual image generation is done in Python. Here's the Github repo in case you want to generate your own images: https://github.com/ept221/julia. Below are some of the generated images (the resolution was reduced so that they could be attached). The burning ship fractal show below uses a different equation than the Mandelbrot set, but only requires one line of the source code to be modified.


Omega Glory:
Here are some created using the equation z = sin(z^2) + c:

golden_labels:
At this point I must link two recent videos from 3blue1brown related to fractals:
* How a Mandelbrot set arises from Newton’s work:
* Newton's Fractal (which Newton knew nothing about): There is bauty beyond the visuals.

And to those, who do not know it yet, I recommend the entire channel. Grant Sanderson has an amazing skill in putting problems into different perspective and conveying concepts.

Nominal Animal:
If you wanted to, you could also use NetPBM P6 (.ppm) output from the C program directly.  These can be compressed to PNG using the NetPBM tools (pnmtopng -compress 9 source.ppm > output.png), but are also directly openable in many applications, like Gimp et cetera.  (You don't need any libraries, only the tools, which are provided by the netpbm package in all Linux distributions.)

The PPM format is very simple.  It has a human-readable header, and image data in uncompressed raw binary form, either 8 bits per component (24 bits per pixel) or 16 bits per component (48 bits per pixel), although not all applications may be able to open the latter.  The exact spec for the P6 format is here.

For an introduction, see e.g. Wikipedia NetPBM article, noting that the examples use P1-P3, or the ASCII formats, not the corresponding binary P4-P6 formats.  The header in all these formats is always in text form. 

You could also memory-map the output file (which could not be a pipe then, though), and let each worker thread just write their output pixel value to the file directly (without seek-read-write overhead, since the data is memory-mapped).  If you initialized the output file to a color value that is not used, you can make it completely restartable too.. The trick with memory-mapping is to use a suitable fixed-size header, say 32 bytes, with padding in the size "row", and to use msync() before unmapping or exiting the program.  I could whip up an example of the mechanism needed, if you like.

SiliconWizard:
I've done something like that a few years ago too. Fractals are fascinating.
As to PNG, I did use libpng directly. It's not that hard to use.

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version