Microsoft Small Basic

Program Listing:
Embed this in your website
' 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()
ANSWER()
DEMO()

Sub ANSWER
  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
  dy=(44/2)*math.sin(Math.GetRadians(angle-90))
  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
    scx=50*math.Cos(math.GetRadians(angle-90))
    scY=50*math.sin(math.GetRadians(angle-90))
    scm[j]=Shapes.AddRectangle(2,5)  ' narrow mark
    If Math.Remainder(j,5)=0 Then    ' 5 pitch
      scm[j]=Shapes.AddRectangle(4,5) ' wide mark
      sct[j]=Shapes.AddText(math.Floor(j/5))
      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"
  msg=shapes.AddText(" ")
  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 -------------------------
  blc[1]= Shapes.AddTriangle(0,0,-10,122,0,122)  ' left
  blc[2]= Shapes.AddTriangle(0,0,10,122,0,122)   ' right
  blc[3]= Shapes.AddRectangle(150,128)   '
  GraphicsWindow.BrushColor="Yellow"
  blc[4]= Shapes.AddEllipse(110,110)   ' circle
  Shapes.SetOpacity(blc[4],70)
  '------------------------ Arrow -------------------------
  GraphicsWindow.BrushColor="Navy"
  GraphicsWindow.PenColor="Navy"
  blc[5]= Shapes.AddTriangle(3,0,0,44,6,44)   ' <----- arrow
  '------------------------ Plate -------------------------
  blc[7]= Shapes.AddRectangle(40,25)
  GraphicsWindow.BrushColor="White"
  GraphicsWindow.PenWidth=5
  blc[8]= Shapes.AddRectangle(200,100)   ' pLATE
  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
    Apl1[i]=Shapes.AddEllipse(30,25)
    Shapes.SetOpacity(APl1[i],70)
    shapes.move(Apl1[i],ax[i],ay[i])
    '
    GraphicsWindow.BrushColor="Pink"
    Apl2[i]=Shapes.AddEllipse(10,8)
    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
    Org1[i]=Shapes.AddEllipse(25,20)
    Shapes.SetOpacity(Org1[i],95)
    shapes.move(Org1[i],bx[i],by[i])
    '
    GraphicsWindow.BrushColor="DarkGreen"
    GraphicsWindow.PenColor="darkGreen"
    Org2[i]=Shapes.Addtriangle(0,0,7,0,3,3)
    Shapes.SetOpacity(Org2[i],95)
    shapes.move(Org2[i],bx[i]+6,by[i]+2)
  EndFor
EndSub

Copyright (c) Microsoft Corporation. All rights reserved.