This is a non-script approach. You can create this fractal adding a tetrahedron with Extra Objects add-on. Then subdivide it once, remove middle triangles and make inner faces. Repeat the subdivide once and makeremove and make faces steps a few times. Scale the fractal down and then animate scaling it up to show the structure.