Fractal Tikz - Polvo de Cantor

Fractal Tikz - Polvo de Cantor

¿Alguien puede ayudarme a dibujar el siguiente fractal en Tikz? ingrese la descripción de la imagen aquí

Aquí comenzamos con el cuadrado unitario, lo dividimos en 16 cuadrados iguales y eliminamos 12 de ellos, dejando 4 ordenados como se ve. El proceso se repite en los cuadrados restantes, y así sucesivamente.

Estoy bastante seguro de que necesito usar algo similar aAnidando decoraciones fractales tikzpero no soy lo suficientemente bueno en TeX para compilar el código yo mismo.

Gracias de antemano.

Mi código hasta ahora:

 \newcommand{\dust}[1]{
     \foreach \i in {1,...,#1}{decorate\{}
     (0,0)--(1,1)
     \foreach \i in {1,...,#1}{\}};

      SOMETHING IN HERE (DON'T KNOW)
 }

 \begin{tikzpicture}
     \path (0,0) pic {dust=5};
 \end{tikzpicture}

Respuesta1

Es un buen ejercicio del sistema Lindenmayer.

\documentclass[border=9,tikz]{standalone}
\usetikzlibrary{lindenmayersystems}
\begin{document}
\pgfdeclarelindenmayersystem{Cantor dust}{
    \symbol{S}{\pgfpathrectangle{\pgfpointorigin}{\pgfpoint{\pgflsystemcurrentstep}{\pgflsystemcurrentstep}}}
    \symbol{U}{\pgftransformyshift{\pgflsystemcurrentstep}}
    \symbol{R}{\pgftransformxshift{\pgflsystemcurrentstep}}
    \rule{S -> [UUSURRS][RSRRUS]}
    \rule{U -> UUUU}
    \rule{R -> RRRR}
}
\tikz;
\tikz\fill[lindenmayer system={Cantor dust,axiom=S,step=320pt,order=1}]lindenmayer system;
\tikz\fill[lindenmayer system={Cantor dust,axiom=S,step= 80pt,order=2}]lindenmayer system;
\tikz\fill[lindenmayer system={Cantor dust,axiom=S,step= 20pt,order=3}]lindenmayer system;
\tikz\fill[lindenmayer system={Cantor dust,axiom=S,step=  5pt,order=4}]lindenmayer system;
\end{document}

Respuesta2

Acabo de descubrir este tema, que estaba relacionado con otro más reciente. Puede considerarse como una aplicación de programación recursiva, para lo cualMetapublicaciónsuele ser muy adecuado. Así que aquí tenéis una solución MetaPost, para quien pueda interesarle.

def cantor_dust(expr x, y, d, n) = 
    if n > 0:
        cantor_dust(x+.25d, y, .25d, n-1);
        cantor_dust(x+.75d, y+.25d, .25d, n-1);
        cantor_dust(x+.5d, y+.75d, .25d, n-1);
        cantor_dust(x, y+.5d, .25d,  n-1);
    else: fill (x, y) -- (x+d, y) -- (x+d, y+d) -- (x, y+d) -- cycle; fi
enddef;
beginfig(1);
    for i = 0 upto 4:
        draw image(cantor_dust(0, 0, 4cm, i)) shifted (4.25cm*i, 0);
    endfor;
endfig;
end.

ingrese la descripción de la imagen aquí

información relacionada