I want to get a colorful triangle like this:
I hope to get a triangle with any number of layers. This is my current method. Actually, I'm not very content with these graph theory functions, since I have to use Quiet
to mute the error information.
pointPair = Subsets[{{0, 0}, {1, Sqrt[3]}, {2, 0}}, {2}];
midPoint[{a_, b_}, {c_, d_}, n_] :=
Transpose[{Subdivide[a, c, n], Subdivide[b, d, n]}]
layers = 8;(*Control the layers*)
poly = Polygon /@
FindClique[
Quiet[NearestNeighborGraph[
Level[RegionIntersection @@@
Subsets[Line /@
Transpose /@
MapAt[Reverse,
Subsets[midPoint[##, layers] & @@@ pointPair, {2}], {2,
2}], {2}], {3}]]], {3}, All];
Graphics[Transpose[{RandomColor[Length[poly]], poly}]]