Let $a,b,c = a_1,a_2,a_3$ and let $i,j,k\in\{1,2,3\}, i\ne j\ne k \ne i$, then:
$$
f(a_1,a_2,a_3)=
\left\{
\begin{array}{ll}
0, & (a_i=a_j=a_k) \\
4, & (a_i+a_j\lt a_k) \lor (a_i=a_j\gt a_k) \\
5, & (a_i+a_j=a_k)\\
8, & (a_i+a_j\gt a_k) \land (a_i\ne a_j\lt a_k)\\
12, & (a_i+a_j\gt a_k) \land (a_i= a_j\lt a_k)
\end{array}
\right.
$$
Works for any $a_1,a_2,a_3\in \mathbb N$.
I ran a python script to generate solutions, then conjectured these patterns based on that data, then reran the script for a lot more solutions to double check the conjecture has no counterexamples.
Finally, what is left is to expand each of the five conditions to get the locations of the intersections explicitly and prove the conjectured patterns.
Update - As requested:
If you are not satisfied with just geometrically reading out the five cases of shapes; You could exhaustively check and confirm all cases - I'm not sure if there is a nicer way?
That is,
Parametrize the line segments in the five shape classes, and compare pairs of segments to see under which conditions they contain an intersection - to get the five cases explicitly.
That is, when observing the $12$ coordinates of points visited by the walk, generally in terms of $a,b,c$:
$$(0,0)\to(0,a)\to(b,a)\to(b,a-c)\to(b-a,a-c)\to(b-a,a-c+b)\to(b-a+c,a-c+b)\to(b-a+c,-c+b)\to(-a+c,-c+b)\to(-a+c,b)\to(c,b)\to(c,0)\to(0,0)$$
You can parametrize the $12$ line segments:
$(0,0)\to(0,a) : (x=0)\land (y\in[0,a] \iff 0\lt y\lt a)$
$(0,a)\to(b,a) : (y=a)\land (x\in[0,b] \iff 0\lt x \lt b)$
$\dots$
And then compare pairs of segments to see under which conditions they can contain an intersection.
For Example, case $f(a,b,c)=12$, we have a geometrical sketch (First, consider $1)\text{ } a\le b\le c$ ):
Now observe under which conditions those intersections exist $(1./12.)$:
$1. : (b-a,a-c+b)$ is a distinct intersection $\iff$ $(x=0=b-a)\land(0 \lt y \lt a, y=a-c+b)$,
Which implies: $a=b$ and $(c\lt a+b \lt a+c)\iff((c\lt a+b)\land(b\lt c))$,
Which agrees with $f(a_1,a_2,a_3)$ when $(a_k=c)\land(a_i=a_j=a=b)$ gives:
$$(a_k\lt a_i+a_j)\land(a_i=a_j\lt a_k)$$
Observing under which conditions those intersections exist $(2./12.)$:
$2. : (-a+c,b)$ is a distinct intersection $\iff$ $(y=b=a)\land(0 \lt x \lt b, x=-a+c)$,
Which implies: $a=b$ and $a\lt c\lt b+a$,
Which agrees with $f(a_1,a_2,a_3)$ when $(a_k=c)\land(a_i=a_j=a=b)$ gives:
$$(a_k\lt a_i+a_j)\land(a_i=a_j\lt a_k)$$
Now, do this for all the rest $3.-12.$ intersections to confirm $f(a,b,c)=12$ for $a\le b\le c$.
$$\dots$$
Then do the same procedure for all other cases of $a_i\le a_j \le a_k$, where $a_i,a_j,a_k\in\{a,b,c\}$ for $1.-12.$, to cover all the other cases - Which I think isn't actually necessary because of symmetry.
$$\dots$$
Finally, you'd have exhaustively checked all possible cases, and arrived at:
$$f(a_1,a_2,a_3)=12 \iff (a_i+a_j\gt a_k) \land (a_i= a_j\lt a_k)$$
In the same way, you can exhaustively check other four cases.
Best Answer
As I understand it, you want a formula to count the number $n$ of triangles that remain at level $k$ in the standard trema construction of the Sierpinski triangle. If we say that level one is the initial triangle, then that leads to a sequence of images that looks like so:
We can then clearly see your formula: $n=3^{k-1}$. (Recall that $3^0=1$, so that $k=1$ yields the correct result.) This depends, however, on where you choose to start counting. I would personally prefer to call the initial triangle level zero but, really, this is somewhat arbitrary.
One other comment: I'm not sure why you're using an unbalanced binary tree to model this situation. It seems to me that a balanced ternary tree (where each node has three children) would be more natural.