The ATMega328P renders the Mandelbrot Fractal

The ATMega328P renders the Mandelbrot Fractal

Posted Apr 26, 2019, 2:26 PM UTC

139
asking_scienceOP•

The ATMega (@16MHz) took 22 minutes to render it

6
waxen_earbuds•

MadneLbrot

3
asking_scienceOP•

Are you dissing my lowercase l? You're dissing my l.

2
PE1NUT•

Not just the lowercase L, look again...

1
asking_scienceOP•

I know about the typo (and I apologised about it in the thread this one is a cross-post of), but my quirky l didn't bother me until you pointed at and made fun of it.

1
polprog•

This is awesome, i wanted to do this since a long time

2
asking_scienceOP•
int iX, iY;
const int iXmax = 320;
const int iYmax = 320;
/* world ( double) coordinate = parameter plane*/
double Cx, Cy;
const double CxMin =0.3586499579;//-0.681249;//-2.5;//-1.264189487;// 
const double CxMax =0.35945193842;//-0.575;// 1.5;//-1.262646922;//
const double CyMin = 0.11175821721;//0.3999;// -2.0;//0.0410344597;//
const double CyMax = 0.11256019771;//0.50625;// 2.0;//0.0425770239;//
/* */
double PixelWidth = (CxMax - CxMin) / iXmax;
double PixelHeight = (CyMax - CyMin) / iYmax;
static unsigned char color[3];
/* Z=Zx+Zy*i  ;   Z0 = 0 */
double Zx, Zy;
double Zx2, Zy2; /* Zx2=Zx*Zx;  Zy2=Zy*Zy  */
int Iteration;
const int IterationMax = 500;
/* bail-out value , radius of circle ;  */
const double EscapeRadius = 2.0;
double ER2 = EscapeRadius*EscapeRadius;
for (iY = 0; iY < iYmax; iY++)
{
    Cy = CyMin + iY*PixelHeight;
    if (fabs(Cy) < PixelHeight / 2) Cy = 0.0; // Main antenna * /
    for (iX = 0; iX < iXmax; iX++)
    {
        Cx = CxMin + iX*PixelWidth;
        //initial value of orbit = critical point Z= 0 * /
        Zx = 0.0;
        Zy = 0.0;
        Zx2 = Zx*Zx;
        Zy2 = Zy*Zy;
      
        for (Iteration = 0; Iteration < IterationMax && ((Zx2 + Zy2) < ER2); Iteration++)
        {
            Zy = 2 * Zx * Zy + Cy;
            Zx = Zx2 - Zy2 + Cx;
            Zx2 = Zx*Zx;
            Zy2 = Zy*Zy;
        };
        // compute  pixel color (24 bit = 3 bytes) * /
        double iterationRatio  = (double)Iteration/(double)IterationMax;
        double green, red, blue;
        if (iterationRatio<=0.5) {
            green = 1.0-(iterationRatio*2);
            red = 1;//iterationRatio*2;
        }
        else {
            green = 0;
            red = 1.0-((0.5-iterationRatio)*2.0);
        }
        double nr, ng;
        nr = 31.0*red;
        ng=61*green;
        //  interior of Mandelbrot set 
        if (Iteration == IterationMax) {
            color[0] = 0;
            color[1] = 0;
            color[2] = 0;
        } else {
            color[0] = (uint8_t) nr;
            color[1] = (uint8_t) ng;
            color[2] = 0;
        }
        plot_pixel((uint16_t)iX,(uint16_t)iY,rgb_565(color[0],color[1],color[2]));
    }
}
2
polprog•

Wow thanks.

How fast is it? Have you tried rewriting it to fixed point arithmetics?

1
asking_scienceOP•

It's extremely fast, probably the fastest algorithm there is for it. Not mine, of course!

fixed point

I've tinkered with the thought (64-bit) but can't justify spending time on it right now, sadly.

1