Erel B4X founder Staff member Licensed User Longtime User Apr 22, 2020 #1 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. Presentation about B4XTurtle: You are welcome to try it and provide feedback. 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 1587567435075.png 25.8 KB · Views: 5,688 Example.zip Example.zip 133.8 KB · Views: 1,380 Last edited: Jul 15, 2020
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. Presentation about B4XTurtle: You are welcome to try it and provide feedback. 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.
walterf25 Expert Licensed User Longtime User Apr 22, 2020 #3 Erel said: Who can draw this star: ? Click to expand... Code: Copy 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 ??? Easy
Erel said: Who can draw this star: ? Click to expand... Code: Copy 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 ??? Easy
Erel B4X founder Staff member Licensed User Longtime User Apr 23, 2020 #4 More elegant Code: Copy DrawStar(200) Sub DrawStar (Size As Int) If Size < 50 Then Return For i = 1 To 5 Turtle.SetPenColor(Rnd(xui.Color_Black, xui.Color_White)) Turtle.MoveForward(Size).TurnLeft(144) DrawStar(Size / 4) Next End Sub
More elegant Code: Copy DrawStar(200) Sub DrawStar (Size As Int) If Size < 50 Then Return For i = 1 To 5 Turtle.SetPenColor(Rnd(xui.Color_Black, xui.Color_White)) Turtle.MoveForward(Size).TurnLeft(144) DrawStar(Size / 4) Next End Sub
ilan Expert Licensed User Longtime User Apr 23, 2020 #5 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: Copy 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
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: Copy 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
barx Well-Known Member Licensed User Longtime User Apr 23, 2020 #6 ilan said: 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: Copy 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 Click to expand... I don't think Turtles can 'run'. I've never seen one run anyway ?
ilan said: 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: Copy 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 Click to expand... I don't think Turtles can 'run'. I've never seen one run anyway ?
ilan Expert Licensed User Longtime User Apr 23, 2020 #7 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: Copy 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: Apr 23, 2020
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: Copy 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.
amidgeha Active Member Licensed User Longtime User Apr 23, 2020 #8 Programmers of all ages and students can use this library to implement the L-system or Lindenmayer system
Programmers of all ages and students can use this library to implement the L-system or Lindenmayer system
Erel B4X founder Staff member Licensed User Longtime User Apr 23, 2020 #9 ilan said: so it means that when the custom view is added it calles immediately the turtle_start event. is it possible to control that? Click to expand... Nothing special. Just raises an event with CallSub. barx said: I don't think Turtles can 'run'. I've never seen one run anyway Click to expand... It will soon have a rabbit mode... There is a use case for this which needs some explanation.
ilan said: so it means that when the custom view is added it calles immediately the turtle_start event. is it possible to control that? Click to expand... Nothing special. Just raises an event with CallSub. barx said: I don't think Turtles can 'run'. I've never seen one run anyway Click to expand... It will soon have a rabbit mode... There is a use case for this which needs some explanation.
rabbitBUSH Well-Known Member Licensed User Longtime User Apr 23, 2020 #10 Erel said: It will soon have a rabbit mode... Click to expand... YES YES YES YES ..??.. recognition! Lets go around the bush again, ?
Erel said: It will soon have a rabbit mode... Click to expand... YES YES YES YES ..??.. recognition! Lets go around the bush again, ?
Erel B4X founder Staff member Licensed User Longtime User Apr 26, 2020 #11 Library reference: https://www.b4x.com/android/forum/threads/?-b4xturtle-reference.116893/ Updates: v1.01 - RabbitMode and other improvements.
Library reference: https://www.b4x.com/android/forum/threads/?-b4xturtle-reference.116893/ Updates: v1.01 - RabbitMode and other improvements.
Erel B4X founder Staff member Licensed User Longtime User Apr 27, 2020 #12 Another quiz: This code draws a circle: Code: Copy Sub Circle For i = 1 to 360 Turtle.MoveForward(1).TurnRight(1) Next End Sub How do we draw a circle with radius = r ? Code: Copy Sub Circle (r As Float) For i = 1 to 360 '?????????? Next End Sub
Another quiz: This code draws a circle: Code: Copy Sub Circle For i = 1 to 360 Turtle.MoveForward(1).TurnRight(1) Next End Sub How do we draw a circle with radius = r ? Code: Copy Sub Circle (r As Float) For i = 1 to 360 '?????????? Next End Sub
LucaMs Expert Licensed User Longtime User Apr 27, 2020 #13 Erel said: How do we draw a circle with radius = r ? Click to expand... ?
Erel B4X founder Staff member Licensed User Longtime User Apr 27, 2020 #15 Can you draw this ? The length of each line is obviously 2 * r.
LucaMs Expert Licensed User Longtime User Apr 27, 2020 #17 Funny; I feel like a kid (almost 60 years old ? . No, only 59.54 y.o. ?) Last edited: Apr 27, 2020
LucaMs Expert Licensed User Longtime User Apr 27, 2020 #18 barx said: I don't think Turtles can 'run'. I've never seen one run anyway Click to expand... Everything is relative: ?_ _ _ ?--> "Look how far that exhibitionist runs" ?
barx said: I don't think Turtles can 'run'. I've never seen one run anyway Click to expand... Everything is relative: ?_ _ _ ?--> "Look how far that exhibitionist runs" ?
ilan Expert Licensed User Longtime User Apr 28, 2020 #20 if the code does not need to be in the for...next loop then it could be done like this: B4X: Copy 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
if the code does not need to be in the for...next loop then it could be done like this: B4X: Copy 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