Microsoft Small Basic

Program Listing: HPW478-0
Debug="false" 'to set to false
args = ""
' full path added by Nonki
' The following line could be harmful and has been automatically commented.
' DebugFile=Program.Directory + "\debugFile.txt"
' The following line could be harmful and has been automatically commented.
' File.DeleteFile(DebugFile)
' The following line could be harmful and has been automatically commented.
' File.AppendContents(DebugFile,"DebugFile : "+Clock.date+" = "+Clock.time)
' The following line could be harmful and has been automatically commented.
' File.AppendContents(DebugFile,"=================================")
if debug then
args = "
TextWindow.top=0
TextWindow.left=800
TextWindow.ForegroundColor = "white"
endif

LDCall.Function("DebugFunc","Hello Small basic I have a problem")

GraphicsWindow.top=0
GraphicsWindow.Left=0
GraphicsWindow.Width=600
GraphicsWindow.Height=600
GraphicsWindow.Title = "kou-ko-gen no teiri"
GraphicsWindow.CanResize="False"
scale=6
Ax=2.019 'A is the point of the ladder on the floor x-axes (2.02..)
Ay=0
Bx=1.20 'B is the point on top of the palette
By=1.50
Cx=0
Cy=4.8
Ladder=5.00
DrawGrid()
'Draw palette
GraphicsWindow.penwidth=1
GraphicsWindow.BrushColor="brown"
GraphicsWindow.FillRectangle(0 ,600-By*600/6,Bx*100,By*100)
'start drawing line
mystep = 0.001
Solx=0
sol1dif=5
soldif2=5
Ax=Bx+.1 'To avoid division by 0
but=6'1.8 'but=6
For Ax=1.21 to but step mystep
LDCall.Function("DebugFunc","42-===========================================")
LDCall.Function("DebugFunc","43-Ax= "+Ax+ " Cy= "+Cy+" Hp = "+Hp)
dif=math.Abs(hp-5)
LDCall.Function("DebugFunc","45-dif= "+dif)
if Ax-Bx < Cy-By then
if dif< sol1dif Then
Soldif1=dif
sol1Ax=Ax
sol1Cy=Cy
sol1Hp=Hp
sol1HP2=Math.SquareRoot(Ax*Ax+Cy*Cy)
LDCall.Function("DebugFunc","51-solution???? Soldif1 = "+Soldif1)' + " sol1dif = "+sol1dif)
LDCall.Function("DebugFunc","53-solution???? = Sol1Ax "+Sol1Ax+ " , "+Sol1Cy+" ; Hp= "+math.abs((hp)-5))
endif
soldif2=5
else
Soldif2=dif
sol2Ax=Ax
sol2Cy=Cy
sol2Hp=Hp
sol2HP2=Math.SquareRoot(Ax*Ax+Cy*Cy)
LDCall.Function("DebugFunc","51-solution???? Soldif2 = "+Soldif2)' + " sol1dif = "+sol1dif)
LDCall.Function("DebugFunc","53-solution???? = Sol1Ax "+Sol1Ax+ " , "+Sol1Cy+" ; Hp= "+math.abs((hp)-5))
endif
DistanceAtoC()
' replaced a little by Nonki
If Hp100=5 Then
GraphicsWindow.PenWidth = 3
Else
GraphicsWindow.PenWidth = 1
EndIf
If myline <> "" And remove Then
Shapes.remove(myline)
EndIf
myline=shapes.addLine(Ax*100,600-Ay*100,Cx*100,600-Cy*100)
If Hp100=5 Then
remove = "False"
Else
remove = "True"
EndIf
'GraphicsWindow.penwidth=1
'myline=shapes.addLine(Ax*100,600-Ay*100,Cx*100,600-Cy*100)
'Shapes.showshape(myline)
' if Hp100=5 then
' GraphicsWindow.penwidth=3
' myline=shapes.addLine(Ax*100,600-Ay*100,Cx*100,600-Cy*100)
' Soly=Cy
' else
' Shapes.remove(myline)
' endif

endfor
program.delay (1000)
'LDCall.Function("DebugFunc","81-solution = "+Solx+ " , "+Soly+" ; Hyp= "+Hp)
LDCall.Function("DebugFunc","82solution (x,y) = "+math.round(Sol1Ax*1000)/1000+ " , "+math.round(Sol1Cy*1000)/1000)
LDCall.Function("DebugFunc","83-solution???? = "+Sol1Ax+ " , "+Sol1Cy+" ; Hp= "+Sol1Hp+" ; Hp2= "+Sol1Hp2)
LDCall.Function("DebugFunc","")
'LDCall.Function("DebugFunc","81-solution = "+Solx+ " , "+Soly+" ; Hyp= "+Hp)
LDCall.Function("DebugFunc","82solution (x,y) = "+math.round(Sol2Ax*1000)/1000+ " , "+math.round(Sol2Cy*1000)/1000)
LDCall.Function("DebugFunc","83-solution???? = "+Sol2Ax+ " , "+Sol2Cy+" ; Hp= "+Sol2Hp+" ; Hp2= "+Sol2Hp2)
'==============================================================
'=================== S U B R O U T I N E S ====================
sub DistanceAtoC
m=(By-Ay)/(Bx-Ax) 'Line equation : y=mx+p ===> m=slope
p=Ay-(m * Ax) 'p=y-mp and Ay=0
p=-m * Ax
Cx=0 'Point C(x,y) is intersection with y-axes
Cy= p
Hp= math.SquareRoot(Ax*Ax + Cy*Cy)
'HP2= 'Hp=Hypothenusa
Hp100=Math.Round(Hp*100)/100 'Hypothenusa rounded at 2 digits behind comma
Hp1000=Math.Round(Hp*1000)/1000 'Hypothenusa rounded at 2 digits behind comma
'TextWindow.ForegroundColor = "Red"
LDCall.Function("DebugFunc","96-Hypothenusa : "+Hp1000)
'TextWindow.ForegroundColor = "White"
yL=(Ladder*Cy)/Math.SquareRoot(Cy*Cy+Ax*Ax)
xL=(yL-p)/m
endsub

Sub DrawGrid
GraphicsWindow.PenColor = "Green"
GraphicsWindow.BrushColor = "Green"
For _x = 0 To 600 Step 100
GraphicsWindow.DrawLine(_x, 0, _x, 600)
If _x=0 Then
GraphicsWindow.DrawText(_x +4, 580, _x/100)
Else
GraphicsWindow.DrawText(_x -10, 580, _x/(100))
EndIf
EndFor
For _y=600 To 0 Step -100
GraphicsWindow.DrawLine(0, _y, 600, _y)
GraphicsWindow.DrawText(4, _y + 4, 6-_y/100)
EndFor
EndSub

Sub DebugFunc
if debug then
TextWindow.WriteLine(args[1])
endif
' The following line could be harmful and has been automatically commented.
' File.AppendContents(DebugFile,args[1])
EndSub