' This program exported from BASIC Anywhere Machine (Version [5.2.3].[2023.12.16.16.28]) on 2023.12.21 at 00:40 (Coordinated Universal Time)
' Rosetta Code Koch curve task
' FreeBASIC program (author unknown) ported to BAM by Charlie Veniot
' https://rosettacode.org/wiki/Koch_curve#FreeBASIC

Const RtoD = 180 / _Pi
Const DtoR = _Pi / 180

Dim As Single posX = 260, posY = 90, angulo = 0

Screen _NEWIMAGE(760,600,12) : Color 0,15

Sub kochLado(longitud As Integer, fondo As Integer)
    Dim As Single dx, dy
    If fondo = 0 Then
        dx = Cos(angulo*DtoR) * longitud
        dy = Sin(angulo*DtoR) * longitud
        Line (posX, posY)⁣-⁣(posX+dx, posY+dy), 0
        posX += dx
        posY += dy
    Else
        kochLado(longitud/3.0, fondo⁣-⁣1)
        angulo += 60
        kochLado(longitud/3.0, fondo⁣-⁣1)
        angulo ⁣-⁣= 120
        kochLado(longitud/3.0, fondo⁣-⁣1)
        angulo += 60
        kochLado(longitud/3.0, fondo⁣-⁣1)
    End If
End Sub

Sub CopoNieveKoch(longitud As Integer, recursionfondo As Integer)
    For i = 1 To 6
        kochLado(longitud,recursionfondo)
        angulo ⁣-⁣= 300
    Next i
End Sub

For n = 0 To 5
    Cls
    Locate 3,4: Print "Copo de nieve de Koch"
    Locate 4,4: Print "Iteracion numero: " + n
    CopoNieveKoch(280, n)
    Sleep 1
Next n
color 4: Locate 6,4: Print "Pulsa una tecla..."
Sleep
End