🐒 B4XTurtle - Library for teachers and parents

inakigarm

Well-Known Member
Licensed User
Longtime User
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)

1588060272059.png
 

LucaMs

Expert
Licensed User
Longtime User
i am sure there is a better and shorter way
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 😴
 

LucaMs

Expert
Licensed User
Longtime User
Just Circle:

B4X:
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
 

ilan

Expert
Licensed User
Longtime User
Why calculate 360 times the "fixed" value: (r*2)/cPI/360? ;)

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.

Just Circle:

B4X:
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

code is to LONG to do only a circle πŸ˜›
 

ilan

Expert
Licensed User
Longtime User
I'm too sleepy. I would say two loops, the external one with a step which is then the limit of the internal loop.
Something like:
B4X:
For i = 0 to AAA Step BBB
    For J = i to i + BBB - 1

actually its very simple:

B4X:
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
 
Top