Turtle graphics is the special drawing
functions
it prepared for the LOGO language.
It was used for artificial intelligence and educational
use.
The cursor like a turtle on
the screen,
advance and rotational directions are
given,
and the orbit will draw a pattern.
In the turtle graphics realized by a
program of 'Basic',
plural tortoises can be moved
at the same time by multi-turtle.
Usage example:
forward 80
right 30
80 move forward and rotate 30
degrees on the right.
It can be used from both command and program
list.
File: "turtle.bas"
load "http://androidbasic.ninja-web.net/sp/turtle.bas"
Version 2013/07/04 or later is required
Command list
The abbreviated form of two characters(Notation[ ]) is
usable, too.
[fd]
forward n - n Move forward.
[bk] back n - n
Move back.
[rt] right n - Right turn n.
[lt] left n - Left turn n.
[wt] wait n - It stop between n.
[pd] pendown - Pen is lowered.
[pu] penup - Pen is raised. The orbital trace
isn't drawn.
[rp] repeat n [ ] - The inside
of brackets is repeated n times and performed.
Multiple structure is
possible.
[cs] cls - Clear screen.
[tc] color n - Color n is chosen.(0~15). Same as
Basic's coloration-col(n).
[pn] pen n - In multiple cursors, No.n cursor is
chosen.
[ps] pos x y - It move to
coordinates(x, y). Cann't change by inside of loop.
[mv] move x y - Only x and y move from current
position.
[ag] angle n - It set to angle n.
[sp] speed n - It set to speed n. (1~10).
larger-faster(default:10)
Variable
It can be used from @0 to
@255.
@v n The value of formula n is
assigned to the variable No.v.
Label & Jump
*label To show a label name in the
alphabet after '*'.
[go] goto
label To jump to the position of specified label.
Conditional branch
if n if the formula n is except '0', the
next command is executed.
if it is '0', it
will skip.
About the value of
formula.
The parameter can use the same formula &
functions as 'Basic'.
Surplus-'mod', so it need a blank
for right and left,
it substitute with '%'.
Variable '@v' can also be used into a formula.
Three functions for exclusive use of
TG are usable, too.
posx(n) To get the
coordinate X of pen n.
posy(n) To get
the coordinate Y of pen n.
angle(n) To
get the angle of pen n.
The
command only for direct
[ld] load
file File is loaded and Executed.
It isn't necessary to
enclose the file name by "".
[md] mode
n Drawing mode change.
0: It
draw with the cursor move animation.
1: It draw in
straight without animation.
The
coordinate origin(0,0) is center of screen,
the right and
upper is Plus, the left and under is Minus.
Upper direction is angle of 0 degrees,
It is clockwise and grow big.(0~359)
The commands can be described to
a text file and can also be executed from the 'load' command.
It divide by space, between commands, between parameters.
e.g.
The
program of star and polygon. (page top)
Execute by 'load tg0.lgo'
file "
tg0.lgo"
pn 1 tc 10 mv 0 180 ag
162 rp 5[fd 352 rt 144]
pn 2 tc 9 mv -193 80 ag 45
rp 8[fd 160 rt 45]
It can
also edit and
save by the editor of Basic for Android.
When line number is attached, it is removed and
loaded.
10 pn 1 tc 10 mv 0 180 ag
162 rp 5[fd 352 rt 144]
20 pn 2 tc 9 mv -193 80 ag
45 rp 8[fd 160 rt 45]
Sample
File [ tg04.bas ]
Load turtle.bas and run, and
enter [ load tg04.bas ] then drawn.
rp 4096[@2 @2+1 @1 @1+@2 @3 @1/1000 @1 (@3-int(@3))*1000 @4
@4+1 tc @4 fd int(@3) rt 1]
File [ tg06.bas
]
Load turtle.bas and run, and enter [ load tg06.bas
] then drawn.
tc 5 @2 1 mv -50 -50 rp 30[@2 @2+1
tc @2 rp 3[fd 100+@1*6 rt 91]@1 @1+1]
File [ tg02.bas ]
30d$="":mode=1
40 'if d$="" then input d$:f=tgcom(d$):goto 40
50 '
100 r=0.6666666666666666
110 ang=20
120 ln2=2
130 f=tgcom("move 0 -160 tc 12")
140
'
150 f=branch(100)
160 '
170 func branch(ln)
180 if
ln<=ln2 then endfunc
190 f=tgcom("forward
"+str$(ln))
200 f=tgcom("left "+str$(ang))
210 f=branch(r*ln)
220
f=tgcom("right "+str$(2*ang))
230 f=branch(r*ln)
240 f=tgcom("left "+str$(ang))
250 f=tgcom("penup back "+str$(ln)+" pendown")
260 endfunc
File [ tg03.bas ]
30d$="":mode=1
40 'if d$="" then input d$:f=tgcom(d$):goto
40
50 '
100 f=tgcom("angle 90 move
-180 -80 tc 14")
110 f=stitch(360)
120 '
130 func stitch(ln)
140 if ln>4 then
150
f=stitch(ln/3)
160 f=tgcom("left 90")
170 f=stitch(ln/3)
180
f=tgcom("right 90")
190 f=stitch(ln/3)
200 f=tgcom("right 90")
210 f=stitch(ln/3)
220
f=tgcom("left 90")
230 f=stitch(ln/3)
240 else
250 f=tgcom("forward
"+str$(ln))
260 endif
270
endfunc
File [ tg06.bas ]
Load turtle.bas and run, and
enter [ load tg06.bas ] then drawn.
rp 36 [rp 34 [fd 12 rt 10] rt 90 @1
@1+1 @2 @1%14+1 tc @2]
[ Back ]