4. Given an equilateral $\triangle A B C$ with side length $6 \sqrt{3}, \odot O$ has a radius of $r$. When the center $O$ moves from point $A$ along the path $A B \rightarrow B C \rightarrow C A$ back to point $A$, $\odot O$ moves with point $O$. Let the area of the part of $\triangle A B C$ that $\odot O$ does not pass through be $S$. When $S>0$, the functional relationship of $S$ with respect to $r$ is $\qquad$
4. $S=3 \sqrt{3}(3-r)^{2}(0<r<3)$  When $r>0$, inside $\triangle ABC$, the part not covered by $\odot O$ forms a regular $\triangle A_{0} B_{0} C_{0}$. The sides of this triangle are parallel to the sides of the original equilateral triangle, and the distance between the parallel lines is $r$.

Connecting $A A_{0}$ and extending it to intersect $B_{0} C_{0}$ and $B C$ at points $E$ and $F$ respectively.
Then $A F \perp B C, A_{0} E \perp B_{0} C_{0}$, and $E F=r$.
Drawing $A_{0} G \perp A B$ at point $G$, then $A_{0} G=r$.
$$
\begin{array}{l}
\text { By } \angle G A A_{0}=30^{\circ} \Rightarrow A A_{0}=2 r \\
\Rightarrow A_{0} E=A F-3 r=9-3 r, \\
B_{0} C_{0}=\frac{2 \sqrt{3}}{3} A_{0} E=2 \sqrt{3}(3-r) \\
\Rightarrow S_{\triangle A_{0} B_{0} C_{0}}=\frac{1}{2} B_{0} C_{0} \cdot A_{0} E=3 \sqrt{3}(3-r)^{2} .
\end{array}
$$

Thus, $S=3 \sqrt{3}(3-r)^{2}(0<r<3)$.