Sign in to follow this  
moc426

Fractal Mandelbrot - Updated 09/15/2007

Recommended Posts

Can you please make this plugin faster? Its a great plugin, and I use it a lot, but its just really, really slow.

It's bound to be a bit slow...it has to run a particular floating-point calculation for each rendered pixel...barring some unknown (and faster) optimization for calculating the value of a point in mandelbrot space, you can probably only go faster with a faster computer.

Share this post


Link to post
Share on other sites

Yah I am not sure if I can improve its performance yet, I haven't looked at that, but it does do a lot of iterations so its bound to be slow. When I have time I will take a look at that.

As for the pan, I can probably setup a pan box like zoom blur deluxe but I don't know about actually rendering a small image of it. But again when time allows.

Can you please make this plugin faster? Its a great plugin, and I use it a lot, but its just really, really slow.

It's bound to be a bit slow...it has to run a particular floating-point calculation for each rendered pixel...barring some unknown (and faster) optimization for calculating the value of a point in mandelbrot space, you can probably only go faster with a faster computer.

Share this post


Link to post
Share on other sites

Thus far all has been dandy regarding speed, even when zooming, and I don't consider my system particularly fast. Looking forward to the updates you have planned, moc426.

Share this post


Link to post
Share on other sites
NOTE: I did not write the mandelbrot function, the function is taken directly from the codelab sample. The function was converted from codelab to c#. Would like to do same for julia function sometime and perhaps follow up with other types. Julia function is a sample in codelab as well so that shouldn't be a problem to setup.

Can you do the same with warp.cs?

Share this post


Link to post
Share on other sites

Completely unrelated to the sample script in codelab, I wrote this code myself.

It continuously color the image through as a gradient and it supports zooming up to 10^16.

The accuracy of the xpan/ypan is to 10^-14

Paste the code into code lab, and experience with the 4 values.

If you keep the values unchanged, and keep adding 0's to the Amount3, you will see a zooming sequence similar to the one in Wikipedia (and it goes to the maximum accuracy - about 10^16) which lands on an island.

I couldn't do any anti-alias to the image, so it might look a bit too sharp.

Example (I made a large image, resize it, and sharpen a little bit):

file.php?mode=view&id=330&sid=3da58550b6fbf65c3fe88b35e7b46ded

long Amount1=74657146173202;	//[-100000000000000, 100000000000000]Xpan
long Amount2=10498959565562;	//[-100000000000000, 100000000000000]Ypan
long Amount3=256;	//[50, 10000000000000000]Zoom
int max = 16384; //[0, 131702]Maximum iteration (Accuracy)
double mod = 256; //value doesn't matter, as long as the variable "mod" is declared

void Render(Surface dst, Surface src, Rectangle rect)
{
   PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds);

   // Delete any of these lines you don't need
   Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();

   long CenterX = (long)(((selection.Right - selection.Left) / 2)+selection.Left);
   long CenterY = (long)(((selection.Bottom - selection.Top) / 2)+selection.Top);
   ColorBgra PrimaryColor = (ColorBgra)EnvironmentParameters.PrimaryColor;
   ColorBgra SecondaryColor = (ColorBgra)EnvironmentParameters.SecondaryColor;
   int BrushWidth = (int)EnvironmentParameters.BrushWidth;

   ColorBgra CurrentPixel;
   for(int y = rect.Top; y < rect.Bottom; y++)
   {
       for (int x = rect.Left; x < rect.Right; x++)
       {
           if (selectionRegion.IsVisible(x, y))
           {
               CurrentPixel = src[x,y];
               ColorBgra prevPix1;
               ColorBgra prevPix2;
               ColorBgra prevPix3;
               if (x > 1 && y > 1)
               {
                   prevPix1 = dst[x-1,y];
                   prevPix2 = dst[x-1,y-1];
                   prevPix3 = dst[x, y-1];
               }
               else
               {
                   prevPix1 = prevPix2 = prevPix3 = dst[x,y];
               }
               double r = (double)(x - CenterX) / Amount3 + ((double)Amount1 / 100000000000000) * (-1);
               double i = (double)(y - CenterY) / Amount3 + ((double)Amount2 / 100000000000000) * (-1);
               double iter = (double)(mandelbrot(r, i));

               CurrentPixel.A = 255;
               CurrentPixel.R = (byte)(getR(iter));
               CurrentPixel.G = (byte)(getG(iter));
               CurrentPixel.B = (byte)(getB(iter));

               dst[x,y] = CurrentPixel;
           }
       }
   }
}
double modular(double iter)
{
   if (iter < 512)
   {
       mod = 256;
       return iter % 256;
   }
   else if (iter < 2048)
   {
       mod = 512;
       return iter % 512;
   }
   else if (iter < 8192)
   {
       mod = 4096;
       return iter % 4096;
   }
   else if (iter < 32768)
   {
       mod = 16384;
       return iter % 16384;
   }
   else
   {
       mod = 65536;
       return iter % 65536;
   }
}
int getR(double iter)
{
   if (iter >= max)
   {
       return 0;
   }
   iter = modular(iter);
   if (iter < mod / 4)
   {
       return 0;
   }
   else if (iter < mod / 2)
   {
       double prev = mod / 4;
       double newIter = iter - prev;

       int col = (int)(newIter * (255 / mod * 4));
       if (col >= 255)
       {
           return 255;
       }
       else
       {
           return col;
       }
   }
   else if (iter < mod / 8 * 5)
   {
       return 255;
   }
   else if (iter < mod)
   {
       return (int)(-1 - (iter - mod / 8 * 5) * (255 / mod * (1 / ((double)3 / 8))));
   }
   return 0;
}
int getG(double iter)
{
   if (iter >= max)
   {
       return 0;
   }
   iter = modular(iter);
   if (iter < mod / 8)
   {
       return 0;
   }
   else if (iter < mod / 8 * 3)
   {
       return (int)((iter - mod / 8) * (255 / mod * 4));
   }
   else if (iter < mod / 16 * 9)
   {
       return 255;
   }
   else if (iter < mod / 8 * 6)
   {
       return (int)(-1 - (iter - mod / 16 * 9) / 2 * (255 / mod * 8));
   }
   else if (iter < mod / 16 * 15)
   {
       return (int)(-1 - (iter - mod / 16 * 15) * (255 / mod * (1 / ((double)12 / 16))));
   }
   return 0;
}
int getB(double iter)
{
   if (iter >= max)
   {
       return 0;
   }
   iter = modular(iter);
   if (iter < mod / 4)
   {
       return (int)((iter + 100) * (255 / (mod / 4 + 100)));
   }
   else if (iter < mod / 2)
   {
       return 255;
   }
   else if (iter < mod / 16 * 9)
   {
       return (int)(-1 - (iter - mod / 2) * (255 / mod * 16));
   }
   else
   {
       return (int)((iter - mod / 16 * 9) / 2 * (255 / mod * (1 / ((double)7 / 16))));
   }
   return 0;
}
int mandelbrot(double r, double i)
{
   double X = r;
   double Y = i;
   double X2 = X * X;
   double Y2 = Y * Y;
   int counter = 0;

   while ((X2 + Y2 < 4) && (counter <= max))
   {
       Y = 2 * X * Y + i;
       X = X2 - Y2 + r;

       X2 = X * X;
       Y2 = Y * Y;

       counter++;
   }

   return counter;
}

3535_b894c262d78f89968d332448af9dd651

Share this post


Link to post
Share on other sites

I´ve got a Problem with this one cuz I downloaded the plugin but when I do it I just get the posibility to change the

-Factor 1-10

-Zoom 1,00-100,00

-Angle

-Quality

thats all I can change on the panel. I don´t even have the X and Y Off spring and that´s often with other tool too that I don´t have the same panel as shown in the tuts

does anyone know why ?

Share this post


Link to post
Share on other sites
moc426, 'Fractal Mandelbrot - Updated 09/15/2007' download link isn't working. is there another place i can go to download it?

It's included in PdN (as stated in the post above yours). :roll:

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this