Introduction

These technical notes explain the basic principles and workings of the secondary equations, the kunge equations. It is not intended as a full guide to the inner workings of gkII, but as a guide to the relationship between the mandelbrot and kunge equations.

It does not give information about how the equations are implimented to use the user parameters or auto layers. That is too much of a mess.

Mandelbrot calculation

Within fractal.c line 175 is the start of a switch statement block, it ends on line 360. Within it are blocks of code sandwiched between 'cases'. Only one case applies for the image to be generated. It depends on the user specification for "kunge type", within the "fractal settings" dialog of gkII.

The default case ("no kunge"), is the standard Mandelbrot plot, here:


   344	        default: /* mandelbrot! */
   345	        for (wz=0; wz < img->depth; wz++) {
*********
   346	            wim = 2.0 * wre * wim + c_im - f_im;
   347	            wre = wre2 - wim2 + c_re - f_re;
   348	            wim2 = wim * wim;
   349	            wre2 = wre * wre;
*********
   350	            if ((wim2 + wre2) > frs_bail) {
   351	                mz = kz = wz;
   352	                mre = lre = kre = krf = wre;
   353	                mim = lim = kim = wim;
   354	                mre2 = lre2 = kre2 = wre2;
   355	                mim2 = lim2 = kim2 = wim2;
   356	                mbail = TRUE;
   357	                break;
   358	            }
   359	        }


c_im = imaginary part of coordinate for mandelbrot/julia set
c_re = real part of coordinate for mandelbrot/julia set
f_im = imaginary perturbation
f_re = real perturbation
wim = 'working' variable for imaginary part of equation ("imag")
wre = 'working' variable for real part of equation ("real")
wim2 = wim * wim ("imag2")
wre2 = wre * wre ("real2")
wz = 'working' Z, iteration ("iter").
frs_bail = bailout value ( default: 4.0 )

As you should expect, the four working variables are initialised with the coordinate of the pixel to be calculated (example for mandelbrot):
wre = x
wim = y
wre2 = x * x
wim2 = y * y

When any of the equations bail, the working variables are copied.

The "Kunge" equation, the second equation

There are five different "kunge" types, these contain the second equation. Only one kunge type is used at a time.

Here is the first "kunge" type. As you can see, the mandelbrot equation (lines 179 - 182) is calculated, and then the "kunge" equation (lines 183 to 186) is calculated:


   177	    case 1: /* mandelbrat xr2 */
   178	        for (wz=0; wz < img->depth; wz++) {
   179	            wim = 2.0 * wre * wim + c_im - f_im;
   180	            wre = wre2 - wim2 + c_re - f_re;
   181	            wim2 = wim * wim;
   182	            wre2 = wre * wre;
*********
   183	            wki = 2 * (wkr - wre) * (wki - wim) + c_im;
   184	            wkr = ((wre2 - wkr) - (wim2 - wki)) + c_re;
   185	            wki2 = wki * wki; 
   186	            wkr2 = wkr * wkr;
*********
   187	            if (mz < 0) { if ((wim2 + wre2) > frs_bail) {
   188	                if (frs_bt == BT_MAND || frs_bt == BT_FIRST)
   189	                        dobail = 0; else dobail--;
   190	                    mbail = TRUE;
   191	                    mz = wz;
   192	                    mre = wre;      mim = wim;
   193	                    mre2 = wre2;    mim2 = wim2; }
   194	            }
   195	            if (kz < 0) { if ((wkr2 + wki2) > frs_bail) {
   196	                if (frs_bt == BT_KUNGE || frs_bt == BT_FIRST)
   197	                        dobail = 0; else dobail--;
   198	                    kbail = TRUE;
   199	                    lre = wre;      lim = wim;
   200	                    lre2 = wre2;    lim2 = wim2;
   201	                    kz = wz;
   202	                    kre = wkr;      kim = wki;
   203	                    kre2 = wkr2;    kim2 = wki2; }
   204	            }
   205	            if (dobail == 0) break;
   206	        }
   207	        break;


wki = 'working' var for imaginary part of kunge equation ("kimag")
wkr = 'working' var for real part of kunge equation ("kreal")
wki2 = wki * wki ("kimag2")
wkr2 = wkr * wkr ("kreal2")

The kunge variables are also initialised:
wki = x
wkr = y
wki2 = x * x
wkr2 = y * y

The bailout condition has radically changed, there are now two bailout conditions which *might* occur independantly of each other. It is the purpose of have a 'working' variable set.

The user can choose the bail type condition to finish the calculation on:
"mandel" - stop when mandel bails.
"kunge" - stop when kunge bails.
"first" - stop as soon as either mandel OR kunge bail.
"both" - stop only when both mandel AND kunge have bailed.

The bailout choices are only for completeness, you could do without them, implimententing bailout only for the kunge equation.


 lre = value of real mandel equation when kunge bails ("lreal")
 lim =   "    " imaginary "   "        "    "     "   ("limag")
 mz  = iteration when mandel bails
 kz  =     "      "   kunge bails

The other four "kunge" types, have a third pair of variables, wkf, and wkf2. What they are, who knows? (real? imaginary?) They have not been made available to the user for plotting with.


"kunge gti":
   214	            wki = 2 * (wkr - wre) * (wki - wim) + c_im;
   215	            wkr = ((wre2 - wkf) - (wim2 - wki)) + c_re;
   216	            wkf = ((wre2 * wkr) - (wim2 * wki)) + c_re;

"kunge afx":
   248	            wki = 2 * (wkr - wre) * (wki - wim) + c_im;
   249	            wkr = pow(wre2, wkf) - pow(wim2, wki) + c_re;
   250	            wkf = wre2 * wkr - wim2 * wki + c_re;

"kunge nsx":
   282	            wki = 2 * (wkr - wre) * (wki - wim) + c_im;
   283	            wkr = pow(wre2, wkf) * pow(wim2, wki) + c_re;
   284	            wkf = (wre2 + wkr) - wim2 * wki + c_re;

"kunge rpm":
   316	            wki = 2 * (wkr - wre) * (wki - wim) + c_im;
   317	            wkr = pow(wre2, wkf) * pow(wim2, wki) + c_re;
   318	            wkf = (wre2 + wkr) * (wim2 + wki) + c_re;