# Create Sierpinski-like triangle in tikz

I would like to adopt this example How to create a Sierpinski triangle in LaTeX?, for a slightly modified Sierpinski triangle: The first step (the whole triangle is black) should be the same. Then in the second step, the three black triangles in the corners should only have a side length of 1/3 (instead of 1/2) of the side length of there "parent" triangle, and so on. Could someone help me with that, i've never used this "lindenmeyersystems" package...

• I do not believe that this graph theory construct can occur. A sierpinski triangle has a color number of 2. What you are describing requires three colors and as such is not longer either a Sierpinski Triangle or even a fractal defined by a lindenmeyar system. Try drawing what you describe by hand and then color in the triangles. May 4 '15 at 20:16
• Here on page 19, you see the triangle, which I tried to describe: books.google.ch/…
– aexl
May 4 '15 at 20:20
• Er... Is that a Lindenmayer system?
– cfr
May 4 '15 at 20:42
• @AlexS A Lindenmayer system is a formal grammar specification of a language. If you want to use the '\usetikzlibrary{lindenmayersystems}' package to draw this triangle then you need to develop the formal math rules that describe this variant of and S-triangle. If you need help with that, then take that question over to the stackoverflow for math of which you are a member. Then return here with a MWE if you have difficulty with the LaTeX implementation. May 4 '15 at 21:58
• @R.Schumacher Oh, I didn't know that lindenberg system is such a thing, I just thought, is is a random name of a tikz package. The script does not have to use this lindenberg system package, I just thought it might be an easy task to adopt the code for drawing the regular sierpinski triangle, but I simply could not understand, what the code exactly does... But thank you for this information, I didn't know this.
– aexl
May 5 '15 at 0:34

Something like that?

Done with MetaPost, inserted in a LuaLaTeX program.

\documentclass[border=2mm]{standalone}
\usepackage{luamplib}
\begin{document}
\begin{mplibcode}
vardef Sierpinski_var(expr A, B, C, n) = % The recursive macro
if n = 0: filldraw A--B--C--cycle;
else:
save AC, BC, AB; pair AC[], BC[], AB[];
AC1 = 1/3[A,C]; AC2 = 2/3[A,C];
BC1 = 1/3[B,C]; BC2 = 2/3[B,C];
AB1 = 1/3[A,B]; AB2 = 2/3[A,B];
draw AB1--AB2; draw BC1--BC2; draw AC1--AC2;
Sierpinski_var(A, AB1, AC1, n-1);
Sierpinski_var(AC2, BC2, C, n-1);
Sierpinski_var(AB2, B, BC1, n-1);
fi
enddef;
beginfig(1);
u = 3cm; n = 4;
pair A, B, C; A = origin; B = u*right; C = u*dir 60;
pair v; v = 1.1u*right; % translation vector
for i = 0 upto 4:
draw image(Sierpinski_var(origin, u*right, u*dir 60, i);
label.bot(textext("$A_" & decimal i & "$"), .5u*right))
shifted (i*v);
endfor;
endfig;
\end{mplibcode}
\end{document}


• Oh wow, this is exactly what I'm looking for. I've never heard of lualatex, what is this exactly? Or what is the difference of the regular latex/pdflatex and lualatex? Is there an easy way to name these triangles with A_1, ..., A_5 below the triangles?
– aexl
May 5 '15 at 0:36
• @AlexS You may consider LuaTeX the successor of pdfTeX: luatex.org One of its nice features is its integration of the MetaPost drawing program, which I used here: en.wikipedia.org/wiki/MetaPost May 5 '15 at 4:02
• As for the labels: Yes it is possible, but not at all levels of recursion of course if they are meant to be all readable. I don't get the logica behing this denomination though: what are A1, A2… supposed to be? Summits or triangles? May 5 '15 at 4:04
• I Just mean to label these steps from the left to the right with A_0, A_1, A_2, A_3 and A_4...
– aexl
May 5 '15 at 13:22
• @AlexS This is done now. May 5 '15 at 15:37