Most likely, you already have heard of the Koch curve or seen it. You basically replace the mid of each line with a triangle line.

So I made a Ti Basic Version of it. Since Recursion is not possible in Basic, I programmed my own iterative solution. Basically its just saving all the lines as connection of two points and then it measures the length and angle of each line in the next iteration and inserts the new lines depending on the angle and the length as points. At the end, you can simply run a plot command to graphically show the fractal, since we already saved all the points, which I think is the fastest way to draw it in Ti Basic.

I already posted it on tibasicdev.wikidot.com, but noone could find a good optimization.

Maybe someone here can think of a better method in Ti Basic or optimize my code a bit. (Maybe it is faster using the Lindenmayer system?)

Since my algorithm slows down exponentially each iteration, because the number of points being stored equals 1+4^N at the Nth iteration, it becomes very slow after a few seconds, but the worst problem here is the max dim of a list (999), which limits it to 4 iterations.

I would appreciate you commenting your opinion on that method or suggesting a better method.

Here is the code btw:

Edit: Oh, and of course I already optimized using the fact that the fractal is symmetrical, meaning you only have to calculate half of the points and then use a mirror algorithm to get the other points (maybe someone knows a better “mirror“ algorithm, I use seq there)

So I made a Ti Basic Version of it. Since Recursion is not possible in Basic, I programmed my own iterative solution. Basically its just saving all the lines as connection of two points and then it measures the length and angle of each line in the next iteration and inserts the new lines depending on the angle and the length as points. At the end, you can simply run a plot command to graphically show the fractal, since we already saved all the points, which I think is the fastest way to draw it in Ti Basic.

I already posted it on tibasicdev.wikidot.com, but noone could find a good optimization.

Maybe someone here can think of a better method in Ti Basic or optimize my code a bit. (Maybe it is faster using the Lindenmayer system?)

Since my algorithm slows down exponentially each iteration, because the number of points being stored equals 1+4^N at the Nth iteration, it becomes very slow after a few seconds, but the worst problem here is the max dim of a list (999), which limits it to 4 iterations.

I would appreciate you commenting your opinion on that method or suggesting a better method.

Here is the code btw:

**Code:**```
Program:Koch (515 Bytes)
```

:Radian

:0→Xmin:0→Ymin:94→Xmax:62→Ymax:AxesOff //friendly window settings

:{0,31+1/3,47,62+2/3,94→L1

:{3,3,18+2/3,3,3→L2

:Plot1(xyLine,L1,L2,° //I used the thinest mark here

:DispGraph

:Repeat getKey

:{0→L3:{3→L4

:For(I,2,1+int(.5dim(L1)))

:L1(I)-L1(I-1

:If Ans:Then

:tan-1((L2(I)-L2(I-1))/Ans→D //D = Angle of line relative to x axis

:Else //prevents Zero Division if a line would go straight up or down

:π/2(1-2(L2(I)<L2(I-1→D

:End

:√((L1(I)-L1(I-1))^2+(L2(I)-L2(I-1))^2→L //phythagorean theorem; use the shorter ^2 token (getkey ID=61)

:√(2/36L^2→T //length of each of the two triangle lines; note, that only the L has to be squared, the 36 is already a 6 squared

:L/3→P //length of each of the two outer lines

:L1(I-1)+Pcos(D→L3(1+dim(L3 //now all line points are being calculated

:L2(I-1)+Psin(D→L4(1+dim(L4

:L3(dim(L3))+Tcos(D+π/4→L3(1+dim(L3

:L4(dim(L4))+Tsin(D+π/4→L4(1+dim(L4

:L3(dim(L3))+Tcos(D-π/4→L3(1+dim(L3

:L4(dim(L4))+Tsin(D-π/4→L4(1+dim(L4

:L1(I→L3(1+dim(L3

:L2(I→L4(1+dim(L4

:End

:augment(L3,seq(94-L3(dim(L3)-X),X,1,dim(L3)-1→L1 //seq creates the symmetry copy of the list

:augment(L4,seq(L4(dim(L4)-X),X,1,dim(L4)-1→L2

:DispGraph

:End

:ZStandart //code after the end is optional, clears everything nice up

:AxesOn

:ClrAllLists

:PlotsOff

:ClrHome

Edit: Oh, and of course I already optimized using the fact that the fractal is symmetrical, meaning you only have to calculate half of the points and then use a mirror algorithm to get the other points (maybe someone knows a better “mirror“ algorithm, I use seq there)