# Microsoft Small Basic

Program Listing:
' Apple ... 300g Orange ....200g Analogue balance Full scale=5000g by NaochanON
' If total weight=3200 , how many apples and oranges ? Arrow angle?
' This program makes answers and demonstrates it.

init()
scaling()
DEMO()

TextWindow.Top=20
TextWindow.Left=700
TextWindow.WriteLine("No Apple Orange Weight Angle ")
For K=0 To 20
For l=0 To 20
W=k*W_APL+L*w_ORG             ' W_APL=300 w_ORG=200
If W=w_TOTAL Then
nn=nn+1
DATK[nn]=K
DATL[nn]=L
Angle=w/w_max*360
TextWindow.WriteLine(nn+" : "+K+ " : "+l+ " : "+w+ " : "+Angle)
W=0
EndIf
EndFor
EndFor
TextWindow.WriteLine(" ")
TextWindow.WriteLine("Now demonstrating ! ")
EndSub

Sub DEMO
For N=1 To nn
For k=0 To DATK[N]
Shapes.Animate(Apl1[k],X-25+15*k,Y-57,500)
Shapes.Animate(Apl2[k],X-25+10+15*k,Y-57,500)
W=k*W_APL
Shapes.SetText(msg,"weight= "+w+" g")
ANGLE=360*W/w_mAX
Program.Delay(500)     ' wait animating time
Move_arrow()
EndFor
'
For L=0 To DATL[N]
W=DATK[N]*W_APL+L*w_ORG
Shapes.SetText(msg,"weight= "+w+" g")
ANGLE=360*W/w_mAX            ' W_mAX=5000
Shapes.Animate(ORG1[l],X-25+10*L,Y-78,500)
Shapes.Animate(ORG2[l],X-25+6+10*L,Y-78+2,500)
Program.Delay(500)     ' wait animating time
Move_arrow()
EndFor
Program.Delay(2000)
return()
EndFor
ENDSUB

Sub return
For k=1 To DATK[N]
Shapes.Animate(Apl1[K],aX[k],ay[k],1000)
Shapes.Animate(Apl2[K],aX[k]+10,ay[k],1000)
EndFor
'--------------------------------------------------
For L=1 To DATL[N]
Shapes.Animate(ORG1[L],bX[L],by[L],1000)
Shapes.Animate(ORG2[L],bX[L]+6,by[L]+2,1000)
EndFor
'--------------------------------------------------
angle=0
Move_arrow()
Shapes.SetText(msg,"weight= 0 g")
endsub

Sub Move_arrow
newX=X+75-3
newy=Y-6+20
dx=(44/2)*math.Cos(Math.GetRadians(angle-90))  ' 44/2 ..... center of arrow length
Shapes.Rotate(blc[5],angle)
Shapes.Move(blc[5],newx+dx,newy+dy+44/2)
EndSub

Sub scaling
GraphicsWindow.BrushColor="Blue"
GraphicsWindow.FontSize=9
For j=1 To 25
angle=360/25*j
If Math.Remainder(j,5)=0 Then    ' 5 pitch
Shapes.Move(sct[j],X+20+55+60/50*scx-2,Y-6+10+55+60/50*scy-2.5)
EndIf
Shapes.Move(scm[j],X+20+55+scx-1,Y-6+10+55+scy-2.5)
Shapes.Rotate(scm[j],angle)
EndFor
EndSub

Sub init
GraphicsWindow.BackgroundColor="Lightcyan"
GraphicsWindow.Width=600
GraphicsWindow.Height=500
GraphicsWindow.Top=20
GraphicsWindow.Left=50
GraphicsWindow.BrushColor="Red"
Shapes.Move(msg,250,230)
W_APL=300                ' Apple weight
w_ORG=200                ' Orange weight
w_TOTAL=3200             ' Total weight
w_mAX=5000               ' full scale
A_balance()              ' draw analoguebalance
fruits()                 ' draw apples and oranges
EndSub

Sub A_balance
X=200
Y=350
GraphicsWindow.BrushColor="Cyan"
GraphicsWindow.PenColor="cyan"
GraphicsWindow.PenWidth=1
'------------------------ body -------------------------
GraphicsWindow.BrushColor="Yellow"
Shapes.SetOpacity(blc[4],70)
'------------------------ Arrow -------------------------
GraphicsWindow.BrushColor="Navy"
GraphicsWindow.PenColor="Navy"
'------------------------ Plate -------------------------
GraphicsWindow.BrushColor="White"
GraphicsWindow.PenWidth=5
Shapes.SetOpacity(blc[8],30)
'---------------------------------------------------------
Shapes.Move(blc[1],X,Y)               ' left triangle
Shapes.Move(blc[2],X+150,Y)           ' right triangle
Shapes.Move(blc[3],X,Y-6)             ' rectangle ( body )
Shapes.Move(blc[4],X+20,Y-6+10)       ' center circle
Shapes.Move(blc[5],X+75-3,Y-6+20)     ' arrow
Shapes.Move(blc[7],X+55,Y-30)         ' rectangle
Shapes.Move(blc[8],X-25,Y-125)        ' plate
EndSub

Sub fruits
' ---------------------- Apple -----------------------
For i=1 To 20
ax[i]=100+15*i
ay[i]=50
GraphicsWindow.BrushColor="Red"
GraphicsWindow.PenColor="Pink"
GraphicsWindow.PenWidth=1
Shapes.SetOpacity(APl1[i],70)
shapes.move(Apl1[i],ax[i],ay[i])
'
GraphicsWindow.BrushColor="Pink"
shapes.move(Apl2[i],ax[i]+10,ay[i])
EndFor
' ---------------------- Orange -----------------------
For i=1 To 20
bx[i]=150+15*i
by[i]=120
GraphicsWindow.BrushColor="Orange"
GraphicsWindow.PenColor="Pink"
GraphicsWindow.PenWidth=1