Is it "normal" that if turtle draws outside canva's pane the results are like that?
If the radius is high, the turtle continue to draw from side's canvas (It seems that should be better not to draw outside the pane and not continue from the other sides of the canvas)
I did it differently because I hoped to be able to make a continuous track, but I don't think it's possible; for this purpose I used the PushState and PopState methods, which allow that "effect".
I hope I haven't written too incomprehensible and illogical things ... I'm sleepy ?
Public Const CLOCKWISE As Int = 1
Public Const COUNTERCLOCKWISE As Int = 2
B4X:
' Wise - pass one of the two contants provided:
' CLOCKWISE or COUNTERCLOCKWISE.
Sub Circle (x As Float, y As Float, r As Float, Wise As Int)
Turtle.SetX(x).SetY(y - r / 2)
If Wise = CLOCKWISE Then
Turtle.SetAngle(0)
Else
Turtle.SetAngle(180)
End If
Dim v As Float = (r * cPI) / 360
For i = 1 To 360
If Wise = CLOCKWISE Then
Turtle.MoveForward(v).TurnRight(1)
Else
Turtle.MoveForward(v).TurnRight(-1)
End If
Next
End Sub
i also used a variable but when i posted the code i wanted it to be as short as possible. you know that's the "key" in a challenge
in real life i would use a variable and do the calculation only once.
Public Const CLOCKWISE As Int = 1
Public Const COUNTERCLOCKWISE As Int = 2
B4X:
' Wise - pass one of the two contants provided:
' CLOCKWISE or COUNTERCLOCKWISE.
Sub Circle (x As Float, y As Float, r As Float, Wise As Int)
Turtle.SetX(x).SetY(y - r / 2)
If Wise = CLOCKWISE Then
Turtle.SetAngle(0)
Else
Turtle.SetAngle(180)
End If
Dim v As Float = (r * cPI) / 360
For i = 1 To 360
If Wise = CLOCKWISE Then
Turtle.MoveForward(v).TurnRight(1)
Else
Turtle.MoveForward(v).TurnRight(-1)
End If
Next
End Sub
That code, as you see, places the turtle in a precise position with respect to the center and allows you to draw both clockwise and counterclockwise. Of course, if you remove the empty lines, it may seem shorter ?
Sub drawwave(r As Float)
Dim oppositedirection As Boolean = True
Turtle.TurnRight(30)
For i = 1 To 2000
If oppositedirection Then Turtle.MoveForward(((r*2)*cPI)/360).TurnLeft(1) Else Turtle.MoveForward(((r*2)*cPI)/360).TurnRight(1)
If i Mod 60 = 0 Then oppositedirection = Not(oppositedirection)
Next
End Sub