# Koch Star

Pattern based on Koch curve

``````def k1 (p:var[]..[])
{
v1 = Vector.ByTwoPoints(p[0],p[1]).Normalized();
d1 = p[0].DistanceTo(p[1]);
p1 = p[0].Translate(v1,d1/3);
v2 = v1.Rotate(Vector.ZAxis(),60);
p2 = p1.Translate(v2,d1/3);
p3 = p1.Translate(v1,d1/3);
return [p[0],p1,p2,p3,p[1]];
};``````

With Loops

``````
def k2 (pts:var[]..[])
{
p1 = List.DropItems(List.Sublists(pts,0..1,1),-1);
p2 = k1(p1<1>);
p3 = Point.PruneDuplicates(List.Flatten(p2,-1),0.1);
};

def k3 (pt:var[]..[],it:int)
{
a = [Imperative]
{
c = 0;
b = [];
while (c < it)
{
b = k2(pt);
pt = b;
c = c + 1;
}
return b;
}
return a;
};``````

With Recursion

``````
def k2(pts:var[]..[],n:int[]..[])
{
a = [Imperative]
{
if (List.Count(pts)>=Math.Pow(5,n))
return pts;
else
{
b = [Associative]
{
p1 = List.DropItems(List.Sublists(pts,0..1,1),-1);
p2 = k1(p1<1>);
p3 = List.Flatten(p2,-1);
return p3;
}
return Point.PruneDuplicates(k2(b,n),0.1);
}
}
b = List.Clean(List.Flatten(a,-1),false);
};``````

Visualization with T-Splines

``````// T Spline Visualization