🐒 B4XTurtle - Library for teachers and parents

Erel

Administrator
Staff member
Licensed User
B4XTurtle is a library inspired by classic Logo programming language and TKP project: http://teachingkidsprogramming.org/
It is a cross platform library.
The purpose of B4XTurtle is to help with teaching programming. Drawing with the turtle is fun and it provides a simple visual feedback to the student.

B4XTurtle is a regular library that you use from B4X. This means that you can use it together with all other B4X features, for example you can download something from the internet and "draw the result".

As you will see once you run the example, the drawing is animated. B4XTurtle maintains a queue of actions and executes them sequentially.

The attached examples show the basic usage of B4XTurtle. More examples will be available soon.

1587567435075.png


You are welcome to try it and provide feedback.

Library reference: https://www.b4x.com/android/forum/threads/🐒-b4xturtle-reference.116893/
Examples: https://www.b4x.com/android/forum/threads/🐒-b4xturtle-examples-for-teachers-and-parents.116979/

Updates:

v1.06 - New StartPolygon and FillPolygon methods - better alternative, in most cases, to the Fill method.
v1.05 - Fixes an issue where the turtle could disappear when moving outside of the visible area, instead of appearing on the other side.
v1.04 - Fixes an issue with Fill which can cause the program to hang.
v1.03 - Multiple layers, DrawBitmap and other improvements.
v1.02 - Fill, Arc and RandomColor
v1.01 - RabbitMode and other improvements.

B4XTurtle is an internal library.
 

Attachments

Last edited:

walterf25

Expert
Licensed User
Who can draw this star:



?
Multiple Star:
    For i = 1 To 5
        canvas.SetPenColor(Rnd(xui.Color_Black, xui.Color_White))
        For j = 1 To 5
            canvas.SetPenColor(Rnd(xui.Color_Black, xui.Color_White))
            canvas.MoveForward(30).TurnLeft(144)
        Next
        canvas.MoveForward(100).TurnLeft(144)
    Next
star.PNG


😁😁😁

Easy
 

ilan

Expert
Licensed User
hi,

i have a question please. when i start the program the turtle starts immediately to run.
but in appstart event (b4j) there is no command for that.

B4X:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Main")
    MainForm.Show
End Sub
so it means that when the custom view is added it calles immediately the turtle_start event. is it possible to control that?

thanx
 
  • Like
Reactions: DMW

barx

Well-Known Member
Licensed User
hi,

i have a question please. when i start the program the turtle starts immediately to run.
but in appstart event (b4j) there is no command for that.

B4X:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Main")
    MainForm.Show
End Sub
so it means that when the custom view is added it calles immediately the turtle_start event. is it possible to control that?

thanx
I don't think Turtles can 'run'. I've never seen one run anyway πŸ˜‚
 

ilan

Expert
Licensed User
actually this lib has a lot potential. i would like to just get positions from the turtle and draw what ever i want like a sprite in a loop.
i will opwn the bas file and see how i can edit it.

like in this event:

B4X:
    If State.PenDown Then
        MainLayer.DrawLine(UserToCanvas(State.UserX), UserToCanvas(State.UserY), UserToCanvas(X), UserToCanvas(Y), State.PenColor, UserToCanvas(State.PenThickness))
    End If
instead of drawing a line i can draw a sprite in a loop.

will check it later when i have more time :)

thanx, erel

EDIT: and also the DrawTurtle event can be used to draw the animated sprite.
 
Last edited:

Erel

Administrator
Staff member
Licensed User
so it means that when the custom view is added it calles immediately the turtle_start event. is it possible to control that?
Nothing special. Just raises an event with CallSub.

I don't think Turtles can 'run'. I've never seen one run anyway
It will soon have a rabbit mode...



There is a use case for this which needs some explanation.
 

ilan

Expert
Licensed User
if the code does not need to be in the for...next loop then it could be done like this:

B4X:
Sub Circle (r As Float)
    For i = 1 To 360
        Turtle.MoveForward(((r*2)*cPI)/360).TurnLeft(1)
    Next
    Turtle.TurnLeft(90).MoveForward(r*2)
    Turtle.PenUp.TurnLeft(180).MoveForward(r)
    Turtle.PenDown.TurnLeft(90).MoveForward(r)
    Turtle.PenUp.TurnLeft(180).MoveForward(r)
    Turtle.PenDown.MoveForward(r)
End Sub
i am sure there is a better and shorter way
 
Top