Saturday 13 February 2010

Mandelbrot Set Sub-sampling

Below is a very basic approach for sub-sampling pixels within the Mandelbrot Set. Instead of iterating through the equation for each pixel, iterate through the equation for each cell of the sub-sample grid and then divide by the number of sub-samples taken.

It's a basic piece of code but the difference between a plot with and a plot without (sub-sampling) is worth waiting that extra bit of processing time for. There are some ways of limiting the sub-sampling to noisy areas only (where it's needed). I'll provide some examples another time.

Let mX let be the x coordinate of the current pixel (the real part of the complex number), let mY be the y coordinate of the current pixel (the imaginary part of the complex number) and let delta be the width/height of a pixel within the plot:

double dDelta = delta/subSamples;
double halfWidth = delta/2.0d;
double total = 0;
for (double xI = 0; xI < subSamples; xI++){
for (double yI = 0; yI < subSamples; yI++){
double pX = mX+(xI*dDelta)-halfWidth;
double pY = mY+(yI*dDelta)-halfWidth;
total += iterate(pX, pY);
}
}
values[screenX, screenY] = total/Math.pow(subSamples, 2);

No comments:

Post a Comment