Fractals that can be implemented via G'MIC-QT

There’s quite a couple of fractals inside G’MIC-QT already such as Thorn Fractal and Mandelbrot set, but they’re not the only ones out there.

Some lists of fractals that can be implemented into G’MIC-QT.

  1. Pickover Popcorn Fractal
#Almost directly translated from C Source Code provided by Paul Bourke. Copy and Paste to code gui filter#
rep_pfrac 50,1,.05,1,0,0,0
rep_pfrac: rep_popcorn_fractal $*
rep_popcorn_fractal:
#$1==points_per_pixels#
#$2==density#
#$3==H#
#$4==zoom#
#$5==rotation_angle#
#$6==origin_x#
#$7==origin_y#
f 0 r 100%,100%,1,1
repeat $! l[$>]
    eval ${-math_lib}"
    const pts=$1;
    const density=1/$2;
    const H=$3;
    const zoom=1/$4;
    const origin_x=$6*-1*zoom;
    const origin_y=$7*zoom;
    const ang=($5/180)*pi;
    const sd=max(w,h)/min(w,h);
    const sx=w>h?sd:1;
    const sy=w>h?1:sd;
    const cx=w/2;
    const cy=h/2;
    const ocx=origin_x*cx;
    const ocy=origin_y*cy;
    const angcondition=($5-360*floor($5/360))?1;
    rot_x(a,b)=a*cos(ang)-b*sin(ang);
    rot_y(a,b)=a*sin(ang)+b*cos(ang);
    for(ix=0,ix<w,ix+=density,
        for(iy=0,iy<h,iy+=density,
            xx=zoom*(ix-cx)/cx;
            yy=zoom*(iy-cy)/cy;
            xx*=sx;
            yy*=sy;
            xx+=origin_x;
            yy+=origin_y;
            for(ptn=0,ptn<pts,ptn++,
                xnew=xx-H*sin(yy+tan(3*yy));
                ynew=yy-H*sin(xx+tan(3*xx));
                xval=((xnew-origin_x*sx)*cx/zoom+cx*sx)/sx;
                yval=((ynew-origin_y*sy)*cy/zoom+cy*sy)/sy;
                if(angcondition,
                    temp_xval=xval-cx+ocx;
                    temp_yval=yval-cy+ocy;
                    xval=rot_x(temp_xval,temp_yval)+cx-ocx;
                    yval=rot_y(temp_xval,temp_yval)+cy-ocy;
                );
                if((round(xval)>=0&&round(yval)>=0)&&(round(xval)<w&&round(yval)<h),
                    i(#0,round(xval),round(yval),0,0)+=1;
                );
                xx=xnew;
                yy=ynew;
            );
        );
    );
    "
endl done
  1. Tetration Fractal - Even Pentation is possible. Sample image below.

2 Likes

Allow me to have fun with it. :stuck_out_tongue:

Church

gmic frac.jpg rotate 90 n 0,255 o frac0.png

Puzzle

gmic frac.jpg +rotate 90 +rotate 180 rotate 45 * n 0,255 o frac1.png

3 Likes

Or maybe a :crown:

1 Like

I see something here…

1024,1024,1,1,"
z = 10*[ x/w, y/h ] -2.5;
for (iter = 0, cabs(z)<=1000000 && iter<256, ++iter, z = z^^(z^^z);
);
iter;
"
k.

So slow though.

Popcorn fractal is being implemented soonly. Next up after is Tetration Fractal. Paul Bourke did released a code, but I don’t know what to make of the complex2polar. I’ll ask @David_Tschumperle what does complex2polar implies?

//h file
typedef struct {
	double x,y;
	double r,t;
} COMPLEX;

COMPLEX ComplexPower(COMPLEX,COMPLEX);
COMPLEX ComplexTetration(COMPLEX,int);
COMPLEX ComplexTetration2(COMPLEX,int);
void Complex2Polar(COMPLEX *);
void Complex2Cart(COMPLEX *);
double ComplexModulus(COMPLEX);

double RealTetration(double,int);

//c file
/*
   Recursive definition for tetration
*/
COMPLEX ComplexTetration(COMPLEX a,int n)
{
   COMPLEX b,unity = {1,0,1,0};

   if (n < 0) // Actually this is improper, tetration is only defined for n >= 0
      n = -n;
   if (n == 0) 
      return(unity);
   b = ComplexPower(a,ComplexTetration(a,n-1));

   return(b);
}

/*
   Iterative definition for tetration
*/
COMPLEX ComplexTetration2(COMPLEX a,int n)
{
   int i;
   COMPLEX b,unity = {1,0,1,0};

   if (n < 0) // Actually this is improper, tetration is only defined for n >= 0
      n = -n;
   if (n == 0)
      return(unity);

   b = a;
   for (i=0;i<n;i++) 
      b = ComplexPower(a,b);
   
   return(b);
}

/*
   Complex power of a complex number
*/
COMPLEX ComplexPower(COMPLEX w,COMPLEX z)
{
   COMPLEX d;
   
   d.r = pow(w.r,z.x) * exp(-z.y * w.t);
   d.t = z.y * log(w.r) + z.x * w.t;
   Complex2Cart(&d);

   return(d);
}

void Complex2Polar(COMPLEX *a)
{
   a->r = sqrt(a->x*a->x + a->y*a->y);
   a->t = atan2(a->y,a->x);
}
void Complex2Cart(COMPLEX *a)
{
   a->x = a->r * cos(a->t);
   a->y = a->r * sin(a->t);
}

/*
   Recursive definition for tetration
*/
double RealTetration(double a,int n)
{
   double b;

   if (n < 0) // Actually this is improper, tetration is only value for n >= 0
      n = -n;
   if (n == 0) 
      return(1);

   b = pow(a,RealTetration(a,n-1));

   return(b);
}

double ComplexModulus(COMPLEX z)
{
   double m;

   m = sqrt(z.x*z.x + z.y*z.y);

   return(m);
}

gmic has complex2polar and polar2complex commands.

#@cli complex2polar
#@cli : Compute complex to polar transforms of selected images.
#@cli : $ image.jpg +fft complex2polar[-2,-1] log[-2] shift[-2] 50%,50%,0,0,2 remove[-1]
complex2polar :
  e[^-1] "Compute complex to polar transforms of image$?."
  repeat int($!/2) l[{2*$>},{2*$>+1}]
    r[1] [0],3 +atan2[1] [0] nm. {1,n} sqr[-3,-2] +[-3,-2] sqrt..
  endl done

#@cli polar2complex
#@cli : Compute polar to complex transforms of selected images.
polar2complex :
  e[^-1] "Compute polar to complex transforms of image$?."
  repeat int($!/2) l[{2*$>},{2*$>+1}]
    r[1] [0],3 +sin. cos.. *. ... *[-3,-2]
  endl done

So, I needed two images? I guess it can be attempted.