[sneak preview] B4XTurtle - library for teaching kids programming

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is an early draft of a new library inspired by Logo programming language and Teaching Kids Programming project: https://teachingkidsprogramming.org/

The idea is to program in B4X language with all of B4X features and to make it very simple to start with something that you can see and play with.

XfMB9VaPxL.gif


It will be cross platform.

Code for this example:
B4X:
Sub Process_Globals
    Private MainForm As Form
    Private Turtle1 As B4XTurtle
    Private xui As XUI
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("1")
    MainForm.Show
    TurtleStart
End Sub

Sub TurtleStart
    Turtle1.X = 20
    Turtle1.Y = 50
    Turtle1.Angle = 90
    Turtle1.MoveForward(230)
    HalfCircle
    HalfCircle
    Turtle1.Y = 50
    Turtle1.X = 140
    Turtle1.Angle = 90
    Turtle1.MoveForward(120)
    Turtle1.TurnLeft(90)
    Turtle1.MoveForward(100)
    Turtle1.X = 200
    Turtle1.Y = 50
    Turtle1.Angle = 90
    Turtle1.MoveForward(220)
    Turtle1.Y = 50
    Turtle1.X = 250
    Turtle1.Angle = 60
    Turtle1.MoveForward(250)
    Turtle1.Y = 50
    Turtle1.Angle = 120
    Turtle1.MoveForward(250)
    Turtle1.PenColor = xui.Color_Blue
    For i = 1 To 2000
        Turtle1.MoveForward(2 - i / 1000)
        Turtle1.TurnLeft(1)
    Next
End Sub

Sub HalfCircle
    Turtle1.Angle = 0
    Turtle1.MoveForward(20)
    For i = 1 To 180
        Turtle1.MoveForward(1)
        Turtle1.TurnLeft(1)
    Next
    Turtle1.MoveForward(20)
End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
bqL8765nmO.gif


B4X:
Sub Turtle1_Start
    Turtle1.SetPenSize(1).SetSpeedFactor(30)
    Turtle1.SetX(Turtle1.Width / 2).SetY(Turtle1.Height - 100)
    Turtle1.TurnLeft(90)
    Tree(13, 100)
End Sub

Sub Tree (Level As Int, Size As Float)
    If Level > 0 Then
        Turtle1.SetPenSize(Level / 2)
        Turtle1.MoveForward(Size).TurnLeft(10)
        Tree(Level - 1, Size * 0.8)
        Turtle1.TurnRight(40)
        Tree(Level - 1, Size * 0.8)
        Turtle1.TurnLeft(30)
        Turtle1.PenUp.MoveBackward(Size).PenDown
    End If
End Sub

Based on: https://personal.utdallas.edu/~veerasam/logo/
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
IGDNxZlJle.gif


B4X:
Sub Button1_Click
    Turtle1.ClearScreen.MoveHome.SetX(Turtle1.Width / 2 - 100)
    For i = 1 To 3
        Turtle1.SetPenSize(4).SetPenColor(Rnd(xui.Color_Black, xui.Color_White))
        KochCurve(5, 400)
        Turtle1.TurnLeft(120)
    Next
End Sub

Sub KochCurve (Level As Int, Size As Float)
    If Level < 1 Then 
        Turtle1.MoveForward(Size)
        Return
    End If
    KochCurve(Level - 1, Size / 3)
    Turtle1.TurnLeft(60)
    KochCurve(Level - 1, Size / 3)
    Turtle1.TurnRight(120)
    KochCurve(Level - 1, Size / 3)
    Turtle1.TurnLeft(60)
    KochCurve(Level - 1, Size / 3)
End Sub
 

walterf25

Expert
Licensed User
Longtime User
Oh man, this is cool, I just started trying to teach my 7 year old daughter, and I can use this now to show her the basic principles, I remember in summer school i took a programming class when I was around 14 years old and we used Logo Writer, which is when I fell in love with programming, great job as always @Erel.

Walter
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Oh man, this is cool, I just started trying to teach my 7 year old daughter, and I can use this now to show her the basic principles, I remember in summer school i took a programming class when I was around 14 years old and we used Logo Writer, which is when I fell in love with programming, great job as always @Erel.
I will release the first version in a day or two. I will need the help of teachers and parents with this project. Please try it when it is released and post your feedback.
 

rabbitBUSH

Well-Known Member
Licensed User
Its simple beauty reminds me of
Those nightmare Recursion exercises in ComSci practice sessions.
🤯
I'll have a go at twisting some poor soul's minds if a chance arises.
 

R D Boozer

Member
Licensed User
I used to teach Logo to children in the early 1980s. A few years later, I spent some time developing what I considered was a more intuitive alternative to it, but I just let it sit. I didn't actually try to get it out there. Anyway, I'll check out your B4X/Logo hybrid when I get a chance.
Thanks. Your experiments are always interesting.
 

PCowling

Member
Licensed User
Longtime User
About 20 years ago when I first started teaching Computing I used to teach fractals in logo to my Year 8 students (12 years old). Love seeing this. As an aside thanks for the algorithms thread and examples, it's brilliant.

In my years teaching I have had two projects completed in B4A as it was, by students, after sharing it with them. Both went onto study Computing at Uni.
 
Top