Microsoft Small Basic

Program Listing: TZJ639
_nln=Text.GetCharacter(13)+Text.GetCharacter(10)
dbg="False"
_hexx="123456789ABCDEF
LDDialogs.Wait("Turtle commander V1.1"+_nln +"(p)2015 by SB community","Green")
Program.Delay(1500)
LDDialogs.EndWait ()
dmt="0=Add/Chng...;1=Diamond;2=MultiDiamnds;3=Lace;4=Spyrall;5=Star5;6=HyperLoop;7=HypFlwrGrid;8=Flwr5;9=Flwr4;10=Clock
dmm=11
vcnt=0
scnt=0
smd=0
rec=0
deff[1]="{10!S 0!R 108!{5 !R 72!F 80!}!##
deff[2]="{5!S 0!{10!R 108!{5 !R 72!F 80!}!}!//!R 144!U!F 210!D!##
deff[3]="{25!S 0!F 30!{3 !R 95!F 140!}!##
deff[4]="{95!S 1.025!R 91.5!F 40!##
deff[5]="{5!R 144!F 140!##
deff[6]="{1!L 40!{55 !S 1.025!R 91.5!F 40!}!//!$!R 90!{55 !R 91.5!F 40!S/1.025!}!//!&!L 90!{55 !R 91.5!F 40!S/1.025!}!//!&!R 90!{55 !L 91.5!F 40!S/1.025!}!##
deff[7]="{1!L 40!{55 !S 1.025!R 91.5!F 40!}!//!$!R 90!{55 !R 91.5!F 40!S/1.025!}!//!&!L 90!{55 !R 91.5!F 40!S/1.025!}!//!&!R 90!{55 !L 91.5!F 40!S/1.025!}!//!&!{55 !L 91.5!F 40!S/1.025!}!//!&!{55 !R 91.5!F 40!S/1.025!}!//!&!R 180!{55 !R 91.5!F 40!S/1.025!}!//!&!R 180!{55 !L 91.5!F 40!S/1.025!}!##
deff[8]="{5!|X1=5!|C2=15!{15 !F %2!R |X1!|X1+1.93!}!##
deff[9]="{4!|X1=5!|C2=15!{15 !F %2!R |X1!|X1+1.76!}!##
deff[10]="{1!~H!|v2=1!|v1=0!|v3=0!|v4=0!D!R 130!{72 !F 11!R 5!}!//!U!R 140!F 33!L 136!{12 !WRT %1!F 55!R 30!|V2+1!}!//!R 45!F 120!R 180!D!~D -50;-20;0!$!{60!~T!|_H:12!|_H*30!|_S~%2!|_S/2!|_H+%3!|_M*6!&!`C Blue!D!R %1!F 60!&!R %2!F 90!R 90!U!{60!R 6!F 10!~1000!}!//!&!D!R %1!P 60!&!R %2!P 90!}!##
_TFL="0=False;1=True;2=True"
stpp=0
Init()

LDDialogs.AddRightClickMenu(dmt,"")
LDDialogs.RightClickMenu=rmm
return=0
args=0

GraphicsWindow.MouseDown=mdd
'GraphicsWindow.MouseMove=mww
GraphicsWindow.MouseUp=muu

Main()

Sub domsg
mtxx="Turtle commander V1.1"+_nln +"(p)2015 by SB community"
If Text.StartsWith(args[1],"$") Then
mtxx=text.GetSubTextToEnd(args[1],2)
Endif
LDDialogs.Wait(mtxx,"Green")
Program.Delay(2500)
LDDialogs.EndWait ()
EndSub

Sub muu
nxt=1
endsub

Sub cang
ox= Turtle.X
oy= Turtle.Y
nx= GraphicsWindow. Mousex
ny= GraphicsWindow. Mousey

ta= Turtle.Angle

aag= 0'mathplus.GetDegrees ( MathPlus.ATan2(nx-ox,ny-oy)+Math.Pi/2) -ta
If aag>180 Then
aag=aag-360
elseIf aag<-180 Then
aag=aag+360

endif
aag=math.Round(aag)
endsub

Sub mww
If rec=1 Then
cang()

GraphicsWindow.Title = aag+" | old:"+Turtle.angle
endif
EndSub

Sub mdd



If mov=1 Then
Turtle.x= GraphicsWindow.MouseX
Turtle.y=GraphicsWindow.MouseY
mov=0


elseif rec=1 and nxt=1 Then
nxt=0
'cang()

ota=turtle.angle
Turtle.Angle=Turtle.Angle+aag
If Turtle.Angle>180 then
Turtle.Angle=Turtle.Angle-360
elseif Turtle.Angle<-180 then
Turtle.Angle=Turtle.Angle+360
endif
nta=turtle.angle
dta=nta-ota
dst=0' Math.SquareRoot ( ESLMaths.Square (GraphicsWindow.MouseX - Turtle.x)+ESLMaths.Square (GraphicsWindow.Mousey - Turtle.y))
dst=math.Round (dst)
Turtle.Move (dst)
dd="R "
If dta<0 then
dd="L "
endif
'TextWindow.WriteLine (aag)
'Clipboard.SetText(cr+dd+Math.Abs(dta)+cr+"F "+dst)
LDFocus.SetFocus(pgm)
' aw = SPExtra.SendKeys("+{INS}")
EndIf

EndSub



Sub findvar

ar=Text.ConvertToUpperCase(args[1])

For ax=1 To vcnt
If Text.ConvertToUpperCase(mem[ax][0])=ar Then
return=ax
Goto xxx
endif
EndFor
TextWindow.WriteLine (ar+" VAR-notfnd!")


return="!VARnotfnd!"
xxx:
endsub

Sub rmm
dd= LDDialogs.LastRightClickMenuItem
if dd>0 Then
LDControls .RichTextBoxSetText(pgm, LDText.Replace ( deff[dd],"!",_nln ),"False")
Else
rr=LDDialogs.Confirm("YES-save NO-load CANC=add","Menu Action:" )

If rr="Yes" Then

' The following line could be harmful and has been automatically commented.
' File.WriteContents ("d:\defs.txt",deff)
' The following line could be harmful and has been automatically commented.
' File.WriteContents ("d:\defm.txt",dmt)

LDCall.Function ("DoMsg","$Saved ok.")
elseIf rr="No" Then

' The following line could be harmful and has been automatically commented.
' deff=File.ReadContents ("d:\defs.txt")
' The following line could be harmful and has been automatically commented.
' dmt=File.ReadContents ("d:\defm.txt")
LDCall.Function ("DoMsg","$Load ok.")
LDDialogs.AddRightClickMenu(dmt,"")
else
li= LDText.Split (src,CR)
att=""
For t=1 To Array.GetItemCount (li)
att=att+li[t]+"!"
endfor
tree=LDControls.TreeViewGetData(trr)

deff[dmm]= att
dmt[dmm]=tree[12][11]
dmm=dmm+1
LDDialogs.AddRightClickMenu(dmt,"")


endif
EndIf

EndSub

Sub hshow
txx= LDText.Split("FWD!BCK!<<>>!LOOP!VAR!CNST!SUB!FOR!GRID!Rec!MvTo!IF!EDIT!OPEN!SAVE!NEW","!")
For x=1 To 17
bb[x]= Controls.AddButton(txx[x], 2, 5+(x-1)*40)
EndFor
EndSub

Sub Main
nwwp:
nww=0
tree=""
tree[1][0]="Main"
tree[2][1]="Defs
tree[3][2]="Heading
tree[4][3]="0
tree[5][2]="Bgrnd
tree[6][5]="#bbccdd
tree[7][2]="ForeClr
tree[8][7]="AUTO
tree[9][2]="Width
tree[10][9]="4
tree[11][1]="Con/Vars
tree[12][11]="0
tree[13][1]="Subs/Lps

mem=0
sbb=0

Goto rr2

rrr:

GraphicsWindow.BackgroundColor =bcll
rr2:
nxt=1
_inn=0
Turtle.Hide()
GraphicsWindow.Clear()

Turtle.Show()
GraphicsWindow.PenWidth=4

Turtle.PenUp ()
Turtle.MoveTo (600,400)
Turtle.PenDown ()
GraphicsWindow.FontName="Calibri"
GraphicsWindow.FontSize=14
hshow()
ch=0
_l=1
sc=1
_sbc=0
GraphicsWindow.BrushColor = "DimGray"
LDControls.RichTextBoxFontFamily="Lucida Console"

LDControls .RichTextBoxFontSize = 18
trr=LDControls.AddTreeView(tree,180,350)
nset()
Controls.Move (trr,50,gh-355)

pgm = ldControls.AddRichTextBox (10, 10)
Controls.SetSize(pgm, 180, gh - 360)
Controls.Move (pgm,50,1)
ldControls.RichTextBoxSetText (pgm, src,"False")
LDControls.RichTextBoxDefault(pgm)
GraphicsWindow.BrushColor = "Black"
g=gh-36
c1= Controls.AddButton("RUN", 2, g)
g=g-35
c2=Controls.AddButton("CLR", 2, g)
g=g-35
c3=Controls.AddButton("XPlain", 2, g)
g=g-35
c4=Controls.AddButton("Paste", 2, g)
g=g-35
c5=Controls.AddButton("? hlp", 2, g)
g=g-35
c6=Controls.AddButton("DrwCh", 2, g)


clicked = "False"
Controls.ButtonClicked = OnButtonClicked
GraphicsWindow.PenColor = "DimGray"

Turtle.Show()
Turtle.PenUp()
Turtle.MoveTo (700,400)
Turtle.PenDown()
Turtle.Angle=0
GraphicsWindow.FontName = "Lucida Console"
GraphicsWindow.FontSize =12
While "True"
If rst=1 Then
src = LDControls .RichTextBoxGetText (pgm)
tree=LDControls.TreeViewGetData(trr)
bcll =tree[6][5]
rst=0
If nww=1 then
Goto nwwp
else
Goto rrr
endif
elseIf clicked Then
Controls.SetButtonCaption(c1,"STOP")
clicked = "False"
src = LDControls .RichTextBoxGetText(pgm)
If Text.GetSubText(src,1,1)="{" or Text.GetSubText(src,1,1)="#" then
If Text.GetSubText(src,1,1)="#" then
dbg="True"
Else
dbg="False"
endif
line= LDText.Split (src,_nln )
rrw= ( text.GetSubTextToEnd(line[1],2))'tonum!
nLines =Array.GetItemCount (line)

If dbg then
TextWindow.WriteLine (">>>>>>>>>>>>>>>>>>>>>runn>>>>>>>>>>>>>>>>>>")
endif
GraphicsWindow.Title="Run mode..."
tree=LDControls.TreeViewGetData(trr)
'TextWindow.WriteLine(tree)
GraphicsWindow.PenWidth=tree[10][9]
'GraphicsWindow.Title=rrw
tree=LDControls.TreeViewGetData(trr)
Turtle.Angle =tree[4][3]
sbscan()
For tt=1 To rrw
vcnt=0
scnt=0
'TextWindow.WriteLine (line)
For i = 2 To rwx
linee=line[i]
If Text.StartsWith(linee,"##") then
Goto finn
elseif Text.StartsWith(linee,"<") then
smd=1
elseif Text.StartsWith(linee,">") then
smd=0
ElseIf smd=0 and stpp=0 then

DoLine()

endif
If stpp=1 then
Controls.SetButtonCaption(c1,"RUN")
stpp=0
GraphicsWindow.Title="Stopped."
clicked="False
Goto wwh
endif
EndFor
finn:
EndFor
tree[4][3]=math.Round (math.Remainder (Turtle.Angle,360))
LDControls.TreeViewContent(trr,tree)
nset()
Controls.SetButtonCaption(c1,"RUN")
GraphicsWindow.Title="Done."
EndIf

Else

EndIf
wwh:
EndWhile
EndSub

Sub sbscan
c=1
rwx=nLines
While Text.StartsWith (line[c],"##")<>"True
c=c+1
If c>nLines then
TextWindow.WriteLine("No ##")
goto tt

endif
EndWhile
rwx=c-1

For i=c To nLines
If Text.StartsWith(line[i], "<") Then
_sbc=_sbc+1
smd=1

sbb[_sbc]["Stt"] = i + 1
For k = i+1 To nLines
If Text.StartsWith(line[k], ">") Then
sbb[_sbc]["End"] = k-1
smd=0
endif

endfor
tree=LDControls.TreeViewGetData(trr)
tnd=Array.GetAllIndices(tree)
nc=array.GetItemCount (tnd)+1
If dbg then
typ="Sb"
sbb[_sbc][0]=Text.GetSubTextToEnd (linee, 2)
tree[nc][13]=typ+":"+_sbc+">"+sbb[_sbc]["Stt"]+" to "+sbb[_sbc]["End"]
LDControls.TreeViewContent(trr,tree)
nset()
endif
endif
endfor
tt:
Endsub

Sub nset
LDControls.TreeViewExpand(trr,0,"True","True")
nn= LDText.Split("4,6,8,10,12",",")
For x=1 To Array.GetItemCount(nn)
LDControls.TreeViewEdit(trr,nn[x],"True")
endfor
EndSub

Sub drwgrd
GraphicsWindow.PenWidth=1
GraphicsWindow.PenColor="#aaaaaa
For x=1 To 70
GraphicsWindow.DrawLine(220+x*20,0,220+x*20,800)
EndFor
For x=1 To 40
GraphicsWindow.DrawLine(220,x*20,1400,x*20)
EndFor

EndSub

Sub xplain
TextWindow.Show ()
TextWindow.Clear()
idd=" "
src = LDControls .RichTextBoxGetText (pgm)
TextWindow.WriteLine("Explain program dump list"+_nln )
line= LDText.Split (Text.ConvertToUpperCase(src),_nln )
rrw= ( text.GetSubTextToEnd(line[1],2))'ToNumber

nLines =Array.GetItemCount (line)
TextWindow.WriteLine ("{Main loop, repeating times:"+rrw)
For i=2 To nLines
linee=line[i]
If Text.StartsWith(linee,"##") then
TextWindow.WriteLine ("} Main loop end.*******************")
else
xpline()
endif
EndFor
endsub

Sub OnButtonClicked
'"FWD!BCK!<<>>!LOOP!VAR!CNST!sub!FOR!SUB!SAVE!LOAD!IF!HLP!NEW"
clb=Controls.LastClickedButton
If clb=c2 then
rst=1
elseIf clb=c3 then
xplain ()
elseIf clb=c4 then
LDControls.RichTextBoxSetText(pgm,Src,"False")
rst=1
elseif clb=bb[1] then

LDControls.RichTextBoxSetText(pgm,"F ","True")

elseif clb=bb[2] then
LDControls.RichTextBoxSetText(pgm,"R 180"+cr+"F "+cr+"R 180","True")
elseif clb=bb[3] then
LDControls.RichTextBoxSetText(pgm,"L ","True")
elseif clb=bb[4] then
LDControls.RichTextBoxSetText(pgm,"R ","True")
elseif clb=bb[5] then
LDControls.RichTextBoxSetText(pgm,"{1 "+cr+"}","True")
elseif clb=bb[6] then
LDControls.RichTextBoxSetText(pgm,"|v1=1","True")

elseif clb=bb[7] then
LDControls.RichTextBoxSetText(pgm,"%1","True")

elseif clb=bb[8] then
ctx=(cr+""+cr)
LDControls.RichTextBoxSetText(pgm,ctx,"True")

elseif clb=bb[9] then
ctx=(cr+"|f1~1"+cr+"FOR %1;10;+1 ["+cr+"]"+cr)
LDControls.RichTextBoxSetText(pgm,ctx,"True")
elseif clb=bb[10] then
DrwGrd()
elseif clb=bb[11] then


elseif clb=bb[12] then
mov=1
elseif clb=bb[13] then
ctx=(cr+"{IF =%1;n;2 "+cr+"//True"+cr+":$2 "+cr+"//False"+cr)
LDControls.RichTextBoxSetText(pgm,ctx,"True")

elseif clb=bb[14] then
Controls.SetSize(pgm,800, gh - 360)
elseif clb=bb[16] then
fnm=LDDialogs.SaveFile("txt","i:\txt")
li= LDText.Split (src,CR)
att=""
For t=1 To Array.GetItemCount (li)
att=att+li[t]+"!"
endfor
' The following line could be harmful and has been automatically commented.
' ss=File.WriteContents(fnm,att)
LDCall.Function ("DoMsg","$Save "+ss)
elseif clb=bb[15] then
fnm=LDDialogs.OpenFile("txt","i:\txt")
' The following line could be harmful and has been automatically commented.
' If ldFile.Exists(fnm) then
' The following line could be harmful and has been automatically commented.
' fcc=File.ReadContents(fnm)
LDControls.RichTextBoxSetText(pgm,fcc,"False")

endif
elseif clb=c5 then
Helpp()
elseif clb=c6 then
tree=LDControls.TreeViewGetData(trr)
cch=tree[12][11]
If text.GetCharacterCode (cch)>32 then
GraphicsWindow.FontName="Times New Roman"
GraphicsWindow.FontSize=540
GraphicsWindow.FontBold="True
GraphicsWindow.FontItalic="True
GraphicsWindow.BrushColor="#bbbbbb
GraphicsWindow.DrawText(300,150,cch)
endif
elseif clb=bb[17] then
rst=1
nww=1
src="{1"+cr
LDControls .RichTextBoxSetText (pgm, src,"False")
else
clicked = "True"
endif
EndSub



Sub DoLine '----------------------------------------------LINEPROC-----------------------------
linee= LDText.Trim (linee)
If linee="" Or Text.StartsWith(linee,"//") Then
Goto exx
endif
If tree[8][7]="AUTO" Then
GraphicsWindow.PenColor=LDColours.HSLtoRGB(math.Remainder (ch,360) ,0.9,0.4)
Else
GraphicsWindow.PenColor=tree[8][7]
endif
ch=ch+1
While Text.IsSubText(linee,"%")
dorepl()
endwhile
ree:
If Text.StartsWith(linee, Text.GetCharacter (34)) Then 'virtual mode
If _inn>0 Then
linee=text.GetSubTextToEnd (linee,2)
Goto ree
Endif
elseIf Text.StartsWith(linee, "|") Then
vn=text.GetSubText(linee,2,2)
vv=text.GetSubTextToEnd (linee,5)
dfc=text.GetSubText(linee,4,1)


If dfc="=" then
vcnt=vcnt+1

mem[vcnt][1]=vv
mem[vcnt][0]=vn
elseif dfc="'" then
rr=ldcall.Function("findvar",vn)
mem[rr][1]=text.GetCharacter (vv)
elseif dfc="." then
pp= (text.GetSubText(linee,5,2))'mathplus.ToNumber
scnt=scnt+1
Matr[scnt]=Text.GetSubTextToEnd ( vv,4)
elseif dfc=";" then

For scnt=1 to Text.GetLength (vv)

Matr[scnt]=Text.GetSubText(vv,scnt,1)
endfor

elseif dfc="+" then
rr=ldcall.Function("findvar",vn)
mem[rr][1]=mem[rr][1]+vv
elseif dfc="~" then
rr=ldcall.Function("findvar",vn)
mem[rr][1]=vv
elseif dfc="*" then
rr=ldcall.Function("findvar",vn)
mem[rr][1]=mem[rr][1]*vv
elseif dfc="/" then
rr=ldcall.Function("findvar",vn)
mem[rr][1]=mem[rr][1]/vv
elseif dfc=":" then
rr=ldcall.Function("findvar",vn)
mem[rr][1]=math.Remainder(mem[rr][1],vv)

endif
ElseIf Text.StartsWith(linee, "~B#") Then 'block wdth
tww= Text.GetSubTextToEnd (linee,4)
ElseIf Text.StartsWith(linee, "WB#") Then 'block txt
ttx= Text.GetSubTextToEnd (linee,4)

GraphicsWindow.DrawBoundText(Turtle.x, Turtle.y,tww,ttx)

ElseIf Text.StartsWith(linee, "#I:") Then 'flickr image get n draw
ttx= Text.GetSubTextToEnd (linee,4)
ppt= LDText.Split(ttx,";")
pim= (Flickr.GetRandomPicture(ppt[1]))
GraphicsWindow.DrawResizedImage(pim,ppt[2],ppt[3],ppt[4],ppt[5])

ElseIf Text.StartsWith(linee, "#P>") Then 'polymode
objm=1
oo=1
Program.Delay(5)
obj[oo][1]=Turtle.X
obj[oo][2]=Turtle.Y
oo=oo+1
ElseIf Text.StartsWith(linee, "#P#") Then 'polymode end
ttx= Text.GetSubTextToEnd (linee,4)
GraphicsWindow.BrushColor=ttx
objm =0
GraphicsWindow .FillTriangle (obj[1][1],obj[1][2],obj[2][1],obj[2][2],obj[3][1],obj[3][2])




ElseIf Text.StartsWith(linee, "#O>") Then 'obj mode
objm=1
oo=1
Program.Delay(5)
obj[oo][1]=Turtle.X
obj[oo][2]=Turtle.Y
oo=oo+1
ElseIf Text.StartsWith(linee, "#O#") Then 'obj mode
ttx= Text.GetSubTextToEnd (linee,4)

objm=0
opp[ttx]=LDShapes.AddPolygon (obj)
LDShapes.BrushColour(opp[ttx],GraphicsWindow.PenColor)

ElseIf Text.StartsWith(linee, "#OM") Then 'obj mode
ttx= Text.GetSubTextToEnd (linee,5)
ttt= LDText.Split (ttx,";")
Shapes.Move (opp[ttt[3]],ttt[1]-obj[1][1],ttt[2]-obj[1][2])

ElseIf Text.StartsWith(linee, "#OA") Then 'obj mode
ttx= Text.GetSubTextToEnd (linee,5)
ttt= LDText.Split (ttx,";")
Shapes.Animate (opp[ttt[3]],ttt[1]-obj[1][1],ttt[2]-obj[1][2],ttt[4])


ElseIf Text.StartsWith(linee, "W#") Then 'console debug writting

ttx= Text.GetSubTextToEnd (linee,3)
If Text.StartsWith (ttx,"|") then
vn=text.GetSubText(ttx,2,2)
ttx=ldcall.Function("findvar",vn)
Endif
TextWindow.WriteLine(">:"+ttx)
ElseIf Text.StartsWith(linee, "WRT") Then
ttx= Text.GetSubTextToEnd (linee,5)
If Text.StartsWith (ttx,"|") then
vn=text.GetSubText(ttx,2,2)
ttx=ldcall.Function("findvar",vn)
Endif
GraphicsWindow.DrawText(Turtle.x, Turtle.y, ttx)
elseif Text.StartsWith(linee, "F") Then
distance = Text.GetSubTextToEnd(linee, 3)
If Text.StartsWith(distance,"|") Then
rr=ldcall.Function("findvar",vn)
dist=mem[rr][1]
Else
dist=distance
endif
Turtle.Move(math.Floor (dist*sc))
if objm=1 then
obj[oo][1]=Turtle.X
obj[oo][2]=Turtle.Y
oo=oo+1
endif
'GraphicsWindow.Title="Dst:"+math.Round ( dist*sc)
if dbg then
TextWindow.WriteLine(math.Floor (dist*sc))
endif

Elseif Text.StartsWith(linee, "S") Then
If Text.GetSubText(linee,2,1)="/" then
sc=sc/ Text.GetSubTextToEnd(linee, 3)
else
sc=sc* Text.GetSubTextToEnd(linee, 3)
endif
If sc=0 then
sc=1
EndIf
ElseIf Text.StartsWith(linee, "$") Then
tx=Turtle.x
ty=Turtle.Y
ta= Turtle.Angle
ts=sc

ElseIf Text.StartsWith(linee, "@") Then ' subbs
scc=Text.GetSubTextToEnd (linee,2)
Sst= sbb[scc]["Stt"]
sen=sbb[scc]["End"]
Stack.PushValue("locali", i)
Stack.PushValue("localj", j)

For i = sSt To sEn
linee=line[i]

_inn=_inn+1
DoLine()
_inn=_inn-1
Endfor
i = Stack.PopValue("locali")+1
j=Stack.PopValue("localj")
ElseIf Text.StartsWith(linee, "&") Then
Turtle.x=tx
Turtle.Y=ty
Turtle.Angle=ta
sc=ts
ElseIf Text.StartsWith(linee, "#X") Then
'FCExtensions.Eval(Text.GetSubTextToEnd(linee, 4))

ElseIf Text.StartsWith(linee, "#E") Then
' mem[1][1]=FCExtensions.MathEval(Text.GetSubTextToEnd(linee, 4))

ElseIf Text.StartsWith(linee, "#F") Then
ff=Text.GetSubTextToEnd(linee, 4)
fn=LDText.Split(ff,";")

GraphicsWindow.FontName=fn[1]
GraphicsWindow.FontBold=_tfl[fn[2]]
GraphicsWindow.FontItalic=_tfl[fn[3]]
GraphicsWindow.FontSize=fn[4]
ElseIf Text.StartsWith(linee, "#P") Then
GraphicsWindow.BrushColor=GraphicsWindow.PenColor
ElseIf Text.StartsWith(linee, "~S") Then
LDQueue.Enqueue("q1",Turtle.x+":"+Turtle.y)
ElseIf Text.StartsWith(linee, "~G") Then
tp=LDQueue.Dequeue ("q1")
tt=LDText.Split(tp,":")
Turtle.x=tt[1]
Turtle.y=tt[2]

ElseIf Text.StartsWith(linee, "#C") Then
ww = ( Text.GetSubTextToEnd(linee, 4))'tonum
GraphicsWindow.BrushColor=GraphicsWindow.PenColor
If ww=0 then
ww=5
endif

GraphicsWindow.FillEllipse(Turtle.x-ww, Turtle.y-ww,ww*2,ww*2)
ElseIf Text.StartsWith(linee, "XC") Then
ww = ( Text.GetSubTextToEnd(linee, 4))'tonum
GraphicsWindow.BrushColor=GraphicsWindow.BackgroundColor
If ww=0 then
ww=5
endif

GraphicsWindow.FillEllipse(Turtle.x-ww, Turtle.y-ww,ww*2,ww*2)
ElseIf Text.StartsWith(linee, "`C") Then
wwc = Text.GetSubTextToEnd(linee, 4)
GraphicsWindow.BrushColor=wwc
GraphicsWindow.penColor=wwc

ElseIf Text.StartsWith(linee, "~D") Then
txy=Text.GetSubTextToEnd(linee, 4)
txm=ldtext.Split(txy,";")
Turtle.x=Turtle.x+txm[1]
Turtle.Y=Turtle.Y+txm[2]
Turtle.Angle=txm[3]

ElseIf Text.StartsWith(linee, "~H") Then

Turtle.x=600
Turtle.Y=400
Turtle.Angle=0

ElseIf Text.StartsWith(linee, "P") Then
GraphicsWindow.PenColor=GraphicsWindow.BackgroundColor
GraphicsWindow.PenWidth=GraphicsWindow.PenWidth+2

distance = Text.GetSubTextToEnd(linee, 3)
If Text.StartsWith(distance,"|") Then
rr=ldcall.Function("findvar",vn)
dist=mem[rr][1]
Else
dist=distance
endif
Turtle.Move(math.Floor (dist*sc))
GraphicsWindow.PenWidth=GraphicsWindow.PenWidth-2

ElseIf Text.StartsWith(linee, "~FN") Then
GraphicsWindow.FontName=Text.GetSubTextToEnd(Linee,5)
ElseIf Text.StartsWith(linee, "~FS") Then
GraphicsWindow.FontSize=Text.GetSubTextToEnd(Linee,5)
ElseIf Text.StartsWith(linee, "~C") Then
ccl=GraphicsWindow.BrushColor
GraphicsWindow.BrushColor =GraphicsWindow.BackgroundColor
GraphicsWindow.FillRectangle (220,200,800,400)
GraphicsWindow.BrushColor=ccl

ElseIf Text.StartsWith(linee, "~T") Then

mem[1][1]=Clock.Hour
mem[1][0]="_H"
mem[2][1]=Clock.Minute
mem[2][0]="_M
mem[3][1]=Clock.Second
mem[3][0]="_S
mem[4][1]=Clock.Date
mem[4][0]="_D"


ElseIf Text.StartsWith(linee, "~") Then
Program.Delay (Text.GetSubTextToEnd(linee, 2))

ElseIf Text.StartsWith(linee, "U") Then
Turtle.PenUp()
ElseIf Text.StartsWith(linee, "D") Then

Turtle.PenDown()
ElseIf Text.StartsWith(linee, "R") Then
distance = Text.GetSubTextToEnd(linee, 3)
If Text.StartsWith(distance,"|") Then
rr=ldcall.Function("findvar",vn)
dist=mem[rr][1]
Else
dist=distance
endif
Turtle.Turn(dist)
ElseIf Text.StartsWith(linee, "L") Then

distance = Text.GetSubTextToEnd(linee, 3)

If Text.StartsWith(distance,"|") Then
rr=ldcall.Function("findvar",vn)
dist=mem[rr][1]
Else
dist=distance
endif
Turtle.Turn(-dist)
ElseIf Text.StartsWith(linee, "A") Then

distance = -Text.GetSubTextToEnd(linee, 3)

If Text.StartsWith(distance,"|") Then
rr=ldcall.Function("findvar",vn)
dist=mem[rr][1]
Else
dist=distance
endif
Turtle.Angle=dist

ElseIf Text.StartsWith(linee, ":$") Then
icc=Text.GetSubTextToEnd (linee, 3)
i=i+icc
ElseIf Text.StartsWith(linee, "IF") Then
icc=Text.GetSubTextToEnd (linee, 4)
iif= LDText.Split(icc,";")


v1=iif[1]
v2=iif[2]

If iif[3]=0 then
skp=2
Else
skp=iif[3]
endif
cond=0
TextWindow.WriteLine ("Sk:"+Skp)

If Text.StartsWith(icc,"=") then
If v1=v2 then
cond=1
Else
cond=2
endif

elseIf Text.StartsWith(icc,">") then
If v1 cond=1
Else
cond=2
endif
elseIf Text.StartsWith(icc,"<") then
If v1>v2 then
cond=1
Else
cond=2
endif
elseIf Text.StartsWith(icc,"!") then
If v1<>v2 then
cond=1
Else
cond=2
endif

endif

If cond=0 then
TextWindow.WriteLine ("IF invalid cond error!")
else
if cond=1 then 'true part
TextWindow.WriteLine ("TRue")
Else 'false part
TextWindow.WriteLine ("Flss")

i=i+skp
endif
endif

ElseIf Text.StartsWith(linee, "{") Then

count[_l] = ( Text.GetSubTextToEnd (linee, 2))'tonum
iStart[_l] = i + 1
iEnd[_l] = nLines
nest = 0

tree=LDControls.TreeViewGetData(trr)
tnd=Array.GetAllIndices(tree)
nc=array.GetItemCount (tnd)+1


For k = iStart[_l] To nLines
'TextWindow.WriteLine(">>"+k)
If Text.StartsWith(line[k], "{") Then
nest = nest + 1
ElseIf Text.StartsWith(line[k], "]") or Text.StartsWith(line[k], "}") Then
If nest = 0 Then
iEnd[_l] = k - 1
k= nLines
Else
nest = nest - 1
EndIf
EndIf
EndFor


If dbg then

typ="Lp"
tree[nc][13]=typ+":"+nest+">"+iStart[_l]+" to "+iEnd[_l]


LDControls.TreeViewContent(trr,tree)
nset()
endif

j = count[_l]
_l = _l + 1
While j>0
Stack.PushValue("local", j)
_inn=_inn+1
For i = iStart[_l - 1] To iEnd[_l - 1]
linee=line[i]
If Text.IsSubText (linee,"%$$") Then
linee=LDText.Replace (linee,"%$$",j)
elseIf Text.IsSubText (linee,"%$A") Then
linee=LDText.Replace (linee,"%$A",Turtle.Angle )
elseIf Text.IsSubText (linee,"%$C") Then
linee=LDText.Replace (linee,"%$C",GraphicsWindow.PenColor )

elseIf Text.IsSubText (linee,"%$") Then
linee=LDText.Replace (linee,"%$","%"+ text.GetSubText (_hexx,j,1) )
endif
If dbg then
TextWindow.WriteLine (i+">>"+linee)
endif

DoLine()
EndFor
_inn=_inn-1
j = Stack.PopValue("local")-1
Endwhile

_l = _l - 1
i = iEnd[_l] + 2
EndIf
exx:
EndSub

Sub dorepl
If Text.IsSubText (linee,"%") Then
aq="!!
If Text.IsSubText(linee,aq) Then
m2=Text.Append("0", mem[2][1])
m2=Text.GetSubTextToEnd (m2,text.GetLength( mem[2][1]))
m3=Text.Append("0", mem[3][1])
m3=Text.GetSubTextToEnd (m3,text.GetLength( mem[3][1]))
endif
If Text.IsSubText (linee,"%1") Then
linee=LDText.Replace (linee,"%1",mem[1][1])
elseIf Text.IsSubText (linee,"%2"+aq) Then
linee=LDText.Replace (linee,"%2"+aq,m2)
elseIf Text.IsSubText (linee,"%3"+aq) Then
linee=LDText.Replace (linee,"%3"+aq,m3)
elseIf Text.IsSubText (linee,"%2") Then
linee=LDText.Replace (linee,"%2",mem[2][1])
elseIf Text.IsSubText (linee,"%3") Then
linee=LDText.Replace (linee,"%3",mem[3][1])

elseIf Text.IsSubText (linee,"%4") Then
linee=LDText.Replace (linee,"%4",mem[4][1])
elseIf Text.IsSubText (linee,"%5") Then
linee=LDText.Replace (linee,"%5",mem[5][1])
elseIf Text.IsSubText (linee,"%6") Then
linee=LDText.Replace (linee,"%6",mem[6][1])
elseIf Text.IsSubText (linee,"%7") Then
linee=LDText.Replace (linee,"%7",mem[7][1])
elseIf Text.IsSubText (linee,"%8") Then
linee=LDText.Replace (linee,"%8",mem[8][1])
elseIf Text.IsSubText (linee,"%9") Then
linee=LDText.Replace (linee,"%9",mem[9][1])
elseIf Text.IsSubText (linee,"%A") Then
linee=LDText.Replace (linee,"%A",mem[10][1])
elseIf Text.IsSubText (linee,"%B") Then
linee=LDText.Replace (linee,"%B",mem[11][1])
elseIf Text.IsSubText (linee,"%C") Then
linee=LDText.Replace (linee,"%C",mem[12][1])
elseIf Text.IsSubText (linee,"%D") Then
linee=LDText.Replace (linee,"%D",mem[13][1])
elseIf Text.IsSubText (linee,"%E") Then
linee=LDText.Replace (linee,"%E",mem[14][1])
elseIf Text.IsSubText (linee,"%F") Then
linee=LDText.Replace (linee,"%F",mem[15][1])
elseIf Text.IsSubText (linee,"%M") Then
mm=text.GetSubTextToEnd(linee,text.GetIndexOf(linee,".")+1)
linee=LDText.Replace (linee,"%M."+mm,matr[(mm)])
elseIf Text.IsSubText (linee,"%X") Then
linee=LDText.Replace (linee,"%X",math.Round (Turtle.x))
elseIf Text.IsSubText (linee,"%Y") Then
linee=LDText.Replace (linee,"%Y",math.Round (Turtle.y))
elseIf Text.IsSubText (linee,"%W") Then
linee=LDText.Replace (linee,"%W",math.Remainder (Turtle.Angle,360) )

endif

endif
endsub

Sub fWriteLn
TextWindow.WriteLine(idd+args[1])
EndSub

Sub xpline '**************************************xplains prg....*********************

If Text.StartsWith(linee, "|") Then
vn=text.GetSubText(linee,2,2)
vv=text.GetSubTextToEnd (linee,5)
dfc=text.GetSubText(linee,4,1)


If dfc="=" then
LDCall.Function("fWriteLn","Define New VAR "+vn+" and assign value:"+vv)
vcnt=vcnt+1
mem[vcnt][0]=vn

elseif dfc="+" then
LDCall.Function("fWriteLn","Increase VAR "+vn+" by:"+vv)



elseif dfc="~" then
LDCall.Function("fWriteLn","Find VAR "+vn+" and assign value:"+vv)
elseif dfc="*" then
LDCall.Function("fWriteLn","Multiply VAR "+vn+" by:"+vv)
elseif dfc="/" then
LDCall.Function("fWriteLn","Divide VAR "+vn+" by:"+vv)
endif
endif
If Text.StartsWith(linee, "W#") Then 'console debug writting

ttx= Text.GetSubTextToEnd (linee,3)

LDCall.Function("fWriteLn","Write to console:"+ttx)
ElseIf Text.StartsWith(linee, "%") then
LDCall.Function("fWriteLn","Perform "+Text.GetSubTextToEnd (linee,4))
ElseIf Text.StartsWith(linee, "WRT") Then 'turtle writting
ttx= Text.GetSubTextToEnd (linee,5)
LDCall.Function("fWriteLn","Write to screen:"+ttx)
ElseIf Text.StartsWith(linee, "Ht") Then
LDCall.Function("fWriteLn","Reset to Home pos.")
elseif Text.StartsWith(linee, "F") Then

dist = Text.GetSubTextToEnd(linee, 3)

If Text.StartsWith(dist,"%") then
dist = "var value:"+mem[Text.GetIndexOf (_hexx, Text.GetSubTextToEnd(dist, 2))][0]
endif
LDCall.Function("fWriteLn","Forward by:"+ dist)
Elseif Text.StartsWith(linee, "<") Then
ttx= Text.GetSubTextToEnd (linee,2)
LDCall.Function("fWriteLn"," idd=idd+" "
Elseif Text.StartsWith(linee, ">") Then
idd=text.GetSubTextToEnd(idd,3)
LDCall.Function("fWriteLn",">END SUB.")
Elseif Text.StartsWith(linee, "]") Then
idd=text.GetSubTextToEnd(idd,4)
LDCall.Function("fWriteLn","] END Repeat block")
Elseif Text.StartsWith(linee, "}") Then
idd=text.GetSubTextToEnd(idd,4)
LDCall.Function("fWriteLn","} END block")

Elseif Text.StartsWith(linee, "S") Then
If sc=0 then
sc=1
LDCall.Function("fWriteLn","Set scale to 1")
else
If Text.GetSubText(linee,2,1)="%" then
LDCall.Function("fWriteLn","Alter scale <(kind +/*) selected by VAR:"+mem[Text.GetIndexOf (_hexx, Text.GetSubText(linee, 3,1))][0]+"> by factor:"+Text.GetSubTextToEnd(linee, 5))
elseIf Text.GetSubText(linee,2,1)="/" then
LDCall.Function("fWriteLn","Divide scale by:"+Text.GetSubTextToEnd(linee, 3))
else
LDCall.Function("fWriteLn","Multiply scale by:"+Text.GetSubTextToEnd(linee, 3))
endif

EndIf
ElseIf Text.StartsWith(linee, "$") Then
LDCall.Function("fWriteLn","Save turtle pos.")

ElseIf Text.StartsWith(linee, "@") Then ' subbs
scc=Text.GetSubTextToEnd (linee,2)
LDCall.Function("fWriteLn","Call sub:"+sbb[scc][0])
ElseIf Text.StartsWith(linee, "&") Then
LDCall.Function("fWriteLn","Restore turtle pos.")
ElseIf Text.StartsWith(linee, "U") Then
LDCall.Function("fWriteLn","Pen UP - moving")
ElseIf Text.StartsWith(linee, "D") Then
LDCall.Function("fWriteLn","Pen DN - drawing")
ElseIf Text.StartsWith(linee, "R") Then
dist = Text.GetSubTextToEnd(linee, 3)
LDCall.Function("fWriteLn","Turn RIGHT by:"+dist)
ElseIf Text.StartsWith(linee, "L") Then
dist = Text.GetSubTextToEnd(linee, 3)
LDCall.Function("fWriteLn","Turn LEFT by:"+dist)


ElseIf Text.StartsWith(linee, "{") Then
LDCall.Function("fWriteLn","{Repeat block times:"+Text.GetSubTextToEnd(linee,2))
idd=idd+" "
EndIf
EndSub'---------------------------------xplain**********************



Sub Init
gw = 1000
gh = 900
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
GraphicsWindow.Title = "Turtle Graphics
GraphicsWindow.BackgroundColor="#bbccdd
GraphicsWindow.Top=0
GraphicsWindow.Left=0
Turtle.Speed=10
CR = _nln
src=LDText.Replace ( deff[8],"!",_nln )
EndSub

Sub Helpp

txx="Spec.vars :"+_nln
txx=txx+">only shows :"+_nln

txx=txx+"%$$ = loop counter backward"+_nln
txx=txx+"%$A = Turtle.Angle"+_nln
txx=txx+"%$C = Pen color"+_nln
txx=txx+"%$n = n=[ 1..F(hex)] ref. in loop to vars 1..15"+_nln
txx=txx+_nln+"Spec.cmds:"+_nln
txx=txx+"%M.nn= matrix row nn _1..99"+_nln
txx=txx+"|vv;txt <= stores txt as chars in matrix %M"+_nln
txx=txx+"|vv~nnn <= stores data in existing var vv"+_nln
txx=txx+"|vv=nnn <= stores data in new var vv"+_nln
txx=txx+"|vv+nnn <= adds value to var vv"+_nln
txx=txx+"|vv*nnn <= multipl. value to var vv"+_nln
txx=txx+"|vv/nnn <= divides var vv by val."+_nln
txx=txx+"|vv'cccc <= stores chr unicode cccc to var vv"+_nln

txx=txx+"~n = delay n msecs"+_nln
txx=txx+"#C ww = fill circle rad.ww px"+_nln
txx=txx+"XC ww = del. circle rad.ww px"+_nln
txx=txx+"~C = del. watch zone"+_nln
txx=txx+"$ = save turtle loc."+_nln
txx=txx+"& = restore turtle loc."+_nln

txx=txx+"#F fnam;bld;itl;siz = set font name, bold 0 or 1, italic 0/1, size"+_nln

txx=txx+"#P = set pen clr from treedef."+_nln
txx=txx+"~H = Home turtle"+_nln
txx=txx+"#E xpr = matheval xpr expression"+_nln
txx=txx+"#X cmd = exec. sb cmd"+_nln

GraphicsWindow.BrushColor = "Black"
GraphicsWindow.FontName = "Tahoma"
GraphicsWindow.FontSize = 15
GraphicsWindow.PenColor="Black
GraphicsWindow.DrawText(310, 20, "S ff | S/ff = scale")
GraphicsWindow.DrawText(310, 40, "F dist=move forward")
GraphicsWindow.DrawText(310, 60, "L|R angle = turn angle")
GraphicsWindow.DrawText(310, 80, "D)wn | U)p = pen mode")
GraphicsWindow.DrawText(310, 105, " GraphicsWindow.DrawText(310, 125, "sub cmds... ")
GraphicsWindow.DrawText(310, 145, "> sub end")
GraphicsWindow.DrawText(310, 165, "@n = sub call n=1..maxnsub by def. order ")

GraphicsWindow.DrawText(310, 190, "{count ")
GraphicsWindow.DrawText(310, 210, "loop cmds ")
GraphicsWindow.DrawText(310, 230, "] or } loop end")

GraphicsWindow.DrawBoundText(310,250,350,txx)


EndSub