Microsoft Small Basic

Program Listing:
Embed this in your website
'Lottery draw demo
'jalpc October 2014
'
numMax=9
speed=200
delay=300
data()
GraphicsWindow.Hide()
formPG()
drawObjects()
GraphicsWindow.Show()
'
Controls.ButtonClicked=OnButtonClicked
'
'Loop
While "True"
  If flag_btnStart Then
    showDemo()
    flag_btnStart="False"
  EndIf
EndWhile
'
''Event's
'====================
'
Sub OnButtonClicked
  If Controls.LastClickedButton=btnStart Then
    flag_btnStart="True"
  Else
    Program.End()
  EndIf
EndSub
'
'Sub's
'====================
Sub showDemo
  GraphicsWindow.Hide()
  GraphicsWindow.Clear()
  data()
  formPG()
  drawObjects()
  Shapes.SetOpacity(btnStart,0)
  GraphicsWindow.Show()
  showRandom()
  Shapes.SetOpacity(btnStart,100)
EndSub
'
Sub showRandom
  For j= 1 To numMax
    'array init
    '--------------
    arr[j] = j
    '---------------
  EndFor
  For item=1 To numMax
    Sound.PlayClickAndWait()
    num=item
    ' get Random
    '-----------------------------------------------------------
    numRandom = Math.GetRandomNumber(numMax)
    '------------------------------------------------------------
    Program.Delay(delay)
    showCounter()
    showNumRandom()
    shadowArray()
    showArrows()
    Program.Delay(delay)
    showRandom_Item()
    showTemp_Item()
    showChangeRandom_Item()
    ' save in temp
    '-----------------------
    temp = arr[item]
    '-----------------------
    showChangeItem_Temp()
    'change Value
    '-------------------------------------
    arr[item] = arr[numRandom]
    '------------------------------------
    showChangeItem_Random()
    Program.Delay(speed)
    showTemp_PosItemRandom()
    showTemp_ItemRandom()
    'change Value
    '------------------------------
    arr[numRandom] = temp
    '-------------------------------
    showChangeTemp_ItemRandom()
  EndFor
  Sound.PlayChimesAndWait()
  For i=1 To 6
    Shapes.SetOpacity(rectEnd,100)
    Program.Delay(300)
    Shapes.SetOpacity(rectEnd,0)
    Program.Delay(300)
  EndFor
  Shapes.SetOpacity(rectEnd,100)
  Shapes.SetOpacity(btnStart,100)
EndSub
'
Sub drawObjects
  param="1=White;2=Red;"
  color()
  Shapes.Remove(rectEnd)
  rectEnd=Shapes.AddRectangle(375,60)
  Shapes.Move(rectEnd,posNumArray_X[1]-20,posNumArray_Y[1]-20)
  Shapes.SetOpacity(rectEnd,0)
  showCounter()
  rectRandom()
  showNumRandom()
  GraphicsWindow.FontSize="15"
  For i = 1 To numMax
    num=i
    param="1=White;2=Black;99=100;"
    color()
    drawRectArray()
    param="1=Black;2=Black;99=100;"
    color()
    drawNumArray()
    param="1=Yellow;2=Black;99=0;"
    color()
    drawTempRectArray()
    param="0=T;1=Red;2=Black;"
    color()
    drawTempNumArray()
    param="0=ยบ;1=Black;2=Black;99=0;"
    color()
    drawArrayOrder()
  EndFor
  btnStart=Controls.AddButton("START",PGW*0.05,PGH-50)
  btnEnd=Controls.AddButton("END",PGW*0.85,PGH-50)
EndSub
'
Sub showArrows
  dif1="1=15;2=-80;3=13;4=-47;"
  dif2="1=-2;2=0;3=9;4=0;5=3;6=5;"
  x1=posRectArray_X[num]+dif1[1]
  y1=posRectArray_Y[num]+dif1[2]
  x2=posRectArray_X[num]+dif1[3]
  y2=posRectArray_Y[num]+dif1[4]
  If num > 5 Then
    x3=195
    y3=100
  Else
    x3=x1
    y3=y1
  EndIf
  param="1=Blue;2=Blue;"
  color()
  Shapes.Remove(linR1)
  linR1=Shapes.AddRectangle(3,40)
  Shapes.Move(linR1,x1,y1)
  Shapes.Remove(linR2)
  linR2=Shapes.AddTriangle(x2+dif2[1],y2+dif2[2],x2+dif2[3],y2+dif2[4],x2+dif2[5],y2+dif2[6])
  Shapes.Remove(linR3)
  widthLin=40*(Math.Abs(num-5))+3
  linR3=Shapes.AddRectangle(widthLin,3)
  Shapes.Move(linR3,x3,y3)
  '
  dif1="1=15;2=72;3=15;4=72;"
  dif2="1=-5;2=6;3=7;4=6;5=1;6=0;"
  x1=posRectArray_X[item]+dif1[1]
  y1=posRectArray_Y[item]+dif1[2]
  x2=posRectArray_X[numRandom]+dif1[3]
  y2=posRectArray_Y[numRandom]+dif1[4]
  If (num-numRandom) > 0 Then
    x=x2
    y=y2
  Else
    x=x1
    y=y1
  EndIf
  param="1=Black;2=Black;"
  color()
  Shapes.Remove(linT1)
  linT1=Shapes.AddRectangle(3,38)
  Shapes.Move(linT1,x1,y1)
  Shapes.Remove(linT2)
  linT2=Shapes.AddRectangle(3,38)
  Shapes.Move(linT2,x2,y2)
  Shapes.Remove(linT3)
  linT3=Shapes.AddTriangle(x2+dif2[1],y2+dif2[2],x2+dif2[3],y2+dif2[4],x2+dif2[5],y2+dif2[6])
  Shapes.Remove(Lin4)
  widthLin=40*(Math.Abs(num-numRandom))+3
  Lin4=Shapes.AddRectangle(widthLin,3)
  Shapes.Move(Lin4,x,y+38)
EndSub
'
Sub formPG
  GraphicsWindow.Left=PGleft
  GraphicsWindow.Top=PGtop
  GraphicsWindow.Width=PGW
  GraphicsWindow.Height=PGH
  GraphicsWindow.Title="Lottery draw demo "
  GraphicsWindow.CanResize="False"
EndSub
'
Sub showCounter   'show counter item's
  cont=cont+1
  param="1=White;2=Red;"
  color()
  GraphicsWindow.DrawRectangle(10,10,rectW*2,rectW*2)
  GraphicsWindow.FillRectangle(15,15,rectW*1.8,rectW*1.8)
  param="1=Red;2=Red;"
  color()
  GraphicsWindow.FontSize="40"
  GraphicsWindow.DrawBoundText(30,20,50,cont)
EndSub
'
Sub rectRandom
  param="1=LightBlue;2=Black;"
  color()
  GraphicsWindow.FillRectangle(100,10,200,50)
  GraphicsWindow.DrawRectangle(100,10,200,50)
  GraphicsWindow.FillRectangle(170,50,50,40)
  GraphicsWindow.DrawRectangle(170,50,50,40)
  param="1=Blue;2=Black;"
  color()
  GraphicsWindow.FontSize="12"
  GraphicsWindow.DrawBoundText(105,12,150,"NUM RANDOM:")
  param="1=Blue;2=Blue;"
  color()
  GraphicsWindow.FillRectangle(195,90,3,10)
EndSub
'
Sub showNumRandom
  param="1=LightBlue;2=Black;"
  color()
  Shapes.Remove(moveRectRandom)
  moveRectRandom=Shapes.AddRectangle(rectW,rectH)
  Shapes.Move(moveRectRandom,posMoveRectRandom_X,posMoveRectRandom_Y)
  param="1=Blue;2=Black;"
  color()
  GraphicsWindow.FontSize=15
  Shapes.Remove(moveRandom)
  moveRandom=Shapes.AddText(numRandom)
  Shapes.Move(moveRandom,posMoveRandom_X,posMoveRandom_Y)
  If numRandom <> "?" Then
    GraphicsWindow.DrawBoundText(95+(item*20),30,20,numRandom)
  EndIf
EndSub
'
Sub drawRectArray
  Shapes.Remove(rectArray[num])
  rectArray[num]=Shapes.AddRectangle(35,30)
  Shapes.Move(rectArray[num],posRectArray_X[num],posRectArray_Y[num])
  Shapes.SetOpacity(rectArray[num],param[99])
EndSub
'
Sub drawNumArray
  Shapes.Remove(arrayNum[num])
  arrayNum[num]=Shapes.AddText(num)
  Shapes.Move(arrayNum[num],posNumArray_X[num],posNumArray_Y[num])
  Shapes.SetOpacity(arrayNum[num],param[99])
EndSub
'
Sub drawTempRectArray
  tempRectArray[num]=Shapes.AddRectangle(35,30)
  Shapes.Move(tempRectArray[num],posTempRectArray_X[num],posTempRectArray_Y[num])
  Shapes.SetOpacity(tempRectArray[num],param[99])
EndSub
'
Sub drawTempNumArray
  Shapes.Remove(tempNumArray[num])
  tempNumArray[num]=Shapes.AddText(param[0])
  Shapes.Move(tempNumArray[num],posTempNumArray_X[num],posTempNumArray_Y[num])
  Shapes.SetOpacity(tempNumArray[num],param[99])
EndSub
'
Sub drawArrayOrder
  GraphicsWindow.DrawBoundText(posNumArray_X[num],posNumArray_Y[num]+120,30,num+param[0])
EndSub
'
Sub shadowArray
  param="1=Magenta;2=Magenta;"
  color()
  GraphicsWindow.DrawRectangle(posRectArray_X[num]+34,posRectArray_Y[num]+2,2,30)
  GraphicsWindow.DrawRectangle(posRectArray_X[num]+3,posRectArray_Y[num]+30,31,2)
  param="1=Black;2=Black;"
  color()
  GraphicsWindow.DrawRectangle(posRectArray_X[num]+3,posRectArray_Y[num]+150,31,1)
EndSub
'
Sub showTemp_Item
  Shapes.SetOpacity(tempRectArray[num],100)
  Shapes.SetOpacity(tempNumArray[num],100)
  Program.Delay(speed)
  Shapes.Animate(tempRectArray[num],posRectArray_X[num],posRectArray_Y[num]+40,speed)
  Shapes.Animate(tempNumArray[num],posNumArray_X[num],posNumArray_Y[num]+40,speed)
  Program.Delay(speed)
EndSub
'
Sub showRandom_Item
  Shapes.Animate(moveRectRandom,posRectArray_X[num],posRectArray_Y[num]-40,speed)
  Shapes.Animate(moveRandom,posNumArray_X[num],posNumArray_Y[num]-40,speed)
  Program.Delay(speed)
EndSub
'
Sub showChangeRandom_Item
  Shapes.Animate(moveRectRandom,posRectArray_X[num],posRectArray_Y[num],speed)
  Shapes.Animate(moveRandom,posNumArray_X[num],posNumArray_Y[num],speed)
  Shapes.Animate(rectArray[num],posRectArray_X[num],posRectArray_Y[num]+40,speed)
  Shapes.Animate(arrayNum[num],posNumArray_X[num],posNumArray_Y[num]+40,speed)
  Program.Delay(speed)
EndSub
'
Sub showChangeItem_Temp
  Shapes.Remove(tempRectArray[num])
  Shapes.Remove(tempNumArray[num])
  param="1=Yellow;2=Black;"
  color()
  tempRectArray[num]=Shapes.AddRectangle(35,30)
  Shapes.Move(tempRectArray[num],posRectArray_X[num],posRectArray_Y[num]+40)
  param="1=Red;2=Black;"
  color()
  tempNumArray[num]=Shapes.AddText(temp)
  Shapes.Move(tempNumArray[num],posNumArray_X[num],posNumArray_Y[num]+40)
EndSub
'
Sub showChangeItem_Random
  Shapes.Remove(rectArray[num])
  Shapes.Remove(arrayNum[num])
  Shapes.Remove(moveRandom)
  param="1=LightBlue;2=Black;"
  color()
  rectArray[item]=Shapes.AddRectangle(35,30)
  Shapes.Move(rectArray[num],posRectArray_X[num],posRectArray_Y[num])
  GraphicsWindow.BrushColor="Blue"
  param="1=Blue;2=Black;"
  color()
  arrayNum[num]=Shapes.AddText(arr[numRandom])
  Shapes.Move(arrayNum[num],posNumArray_X[num],posNumArray_Y[num])
  moveRandom=Shapes.AddText("?")
  Shapes.Move(moveRandom,posMoveRandom_X,posMoveRandom_Y)
  Shapes.Move(moveRectRandom,posMoveRectRandom_X,posMoveRectRandom_Y)
EndSub
'
Sub showTemp_PosItemRandom
  Shapes.Animate(tempRectArray[num],posRectArray_X[numRandom],posRectArray_Y[numRandom]+40,speed)
  Shapes.Animate(tempNumArray[num],posNumArray_X[numRandom],posNumArray_Y[numRandom]+40,speed)
  Program.Delay(speed)
EndSub
'
Sub showTemp_ItemRandom
  Shapes.Animate(tempRectArray[num],posRectArray_X[numRandom],posRectArray_Y[numRandom],speed)
  Shapes.Animate(tempNumArray[num],posNumArray_X[numRandom],posNumArray_Y[numRandom],speed)
  Program.Delay(speed)
EndSub
'
Sub color
  GraphicsWindow.BrushColor=param[1]
  GraphicsWindow.PenColor=param[2]
EndSub
'
Sub showChangeTemp_ItemRandom
  Shapes.Remove(rectArray[numRandom])
  Shapes.Remove(arrayNum[numRandom])
  Shapes.Remove(tempNumArray)
  param="1=Yellow;2=Black;"
  color()
  rectArray[numRandom]=Shapes.AddRectangle(35,30)
  Shapes.Move(rectArray[numRandom],posRectArray_X[numRandom],posRectArray_Y[numRandom])
  param="1=Red;2=Black;"
  color()
  arrayNum[numRandom]=Shapes.AddText(temp)
  Shapes.Move(arrayNum[numRandom],posNumArray_X[numRandom],posNumArray_Y[numRandom])
  GraphicsWindow.PenColor="Black"
  param="1=Yellow;2=Black;"
  color()
  tempNumArray[item]=Shapes.AddRectangle(35,30)
  Shapes.Move(tempNumArray[num],posTempNumArray_X[num],posTempNumArray_Y[num])
  Shapes.SetOpacity(tempNumArray[num],0)
EndSub
'
Sub data
  cont=-1
  numRandom="?"
  PGleft=40
  PGtop=5
  PGW=400
  PGH=430
  rectW=35
  rectH=30
  posMoveRectRandom_X=177
  posMoveRectRandom_Y=55
  posMoveRandom_X=191
  posMoveRandom_Y=60
  For numItem = 1 To numMax
    posRectArray_X[numItem]=40*numItem-20
    posRectArray_Y[numItem]=180
    posNumArray_X[numItem]=posRectArray_X[numItem] + 10
    posNumArray_Y[numItem]=posRectArray_Y[numItem] + 6
    posTempRectArray_X[numItem]=posRectArray_X[numItem]
    posTempRectArray_Y[numItem]=posRectArray_Y[numItem]+160
    posTempNumArray_X[numItem]=posNumArray_X[numItem]
    posTempNumArray_Y[numItem]=posNumArray_Y[numItem]+160
  EndFor
EndSub

Copyright (c) Microsoft Corporation. All rights reserved.