Microsoft Small Basic

Program Listing:
Embed this in your website
'Yandee Man. Draw a face using ellipses and Animate the face to move on the screen.
'September 2013 - Curriculum Challenge

'------------------------------------------Events----------------------------------------------
Controls.ButtonClicked = OnButtonClick
Timer.Tick = OnTick

'---------------------------------------Event Handlers-----------------------------------------
Sub OnButtonClick
  flag = "toggleGW"
EndSub

Sub OnTick
  flag = "blink"
  Timer.Pause()
EndSub

'--------------------------------------Initialise Variables------------------------------------
Timer.Interval = 2000
Timer.Pause()

DataTable()

toggleGW = -1   'toggles on start. ------ Initialise for InitGW()

bY = 0.1      'opn=1 , close=0.1 ------- Initialise for Blink()
bX = 0.8      'opn=0.2, close=0.8
delta = 0.01

flag = "toggleGW"

'==========================Event Loop========================
While "true
  If flag = "toggleGW" Then
    InitGW()
    RemoveFace()
    InitFace()   'includes RefreshButton() -adds on top
    RevealFace()
    flag = "blink"
  ElseIf flag = "blink" Then
    Blink()
  EndIf
  Program.Delay(5)
EndWhile

'--------------------------------------------Subroutines-----------------------------------------
Sub Blink
  If bY = 1  Then
    delta = -delta
    Timer.Resume()
    flag = 0
  ElseIf bY = 0.1 Then
    delta = -delta
  EndIf
  bY = bY - delta
  bX = bX + (delta*0.7)
  For i = 6 To 7
    Shapes.Zoom(shp[i], 1, bY)
    Shapes.Zoom(shp[i+2], bX, bY)
  EndFor
EndSub

Sub RevealFace
  zoom = 0
  opacity = 0  '----- reveal all & zoom in to 1
  While opacity < 100
    opacity = opacity + 4
    zoom = zoom + 0.04
    For i = 1 To Array.GetItemCount(F)
      Shapes.SetOpacity(shp[i], opacity)
      Shapes.Zoom(shp[i], zoom, zoom)
    EndFor
    Program.Delay(1)
  EndWhile
EndSub

Sub InitFace
  indices = Array.GetAllIndices(F)  'index shapes Z-order w/integers

  For i = 1 To Array.GetItemCount(F) 'initial setup of shapes - pos & invisible
    z = indices[i]
    If gwSize = 2 And z = "headTopCovr" Then
      GraphicsWindow.BrushColor = GW["small"][1]["BGC"]
    Else
      GraphicsWindow.BrushColor = F[z]["C"]
    EndIf
    shp[i] = Shapes.AddEllipse(F[z]["W"], F[z]["H"])
    Shapes.Move(shp[i], F[z]["X"]+offSetX,F[z]["Y"]+offSetY)
    Shapes.Rotate(shp[i], F[z]["R"])
    Shapes.SetOpacity(shp[i], 0) '0
  EndFor
  RefreshButton()
EndSub

Sub RemoveFace
  For i = 1 To Array.GetItemCount(F)
    Shapes.Remove(shp[i])
  EndFor
EndSub

Sub DataTable
  GW["big"][1]     = "W=500;H=500;PW=0;BGC=black;RS=0;BC=Crimson"
  GW["big"][2]     = "T=Songline Software - Big Black Window"
  GW["small"][1]   = "W=380;H=300;PW=0;BGC=white;RS=0;BC=black"
  GW["small"][2]   = "T=Songline Software - Small White Window"
  ' -- Z --
  F["leftEar"]     = "W=20;H=50;C=SpringGreen;Op=0;X=162;Y=120;R=0"           '1
  F["rightEar"]    = "W=20;H=50;C=SpringGreen;Op=0;X=318;Y=120;R=0"           '2
  F["face"]        = "W=150;H=200;C=Green;Op=0;X=175;Y=50;R=0"                '3
  F["headTopCovr"] = "W=350;H=110;C=black;Op=0;X=75;Y=50;R=0"                 '4
  F["headTop"]     = "W=150;H=60;C=Green;Op=0;X=175;Y=129;R=0"                '5
  F["leftEye"]     = "W=40;H=30;C=DarkMagenta;Op=0;X=190;Y=145;R=10;bY=0.1"   '6
  F["rightEye"]    = "W=40;H=30;C=DarkMagenta;Op=0;X=270;Y=145;R=-10;bY=0.1"  '7
  F["leftPupil"]   = "W=35;H=30;C=Yellow;Op=0;X=193;Y=145;R=0;bX=0.8"         '8
  F["rightPupil"]  = "W=35;H=30;C=Yellow;Op=0;X=272;Y=145;R=0;bX=0.8"         '9
EndSub

Sub InitGW
  toggleGW = -toggleGW
  If toggleGW = 1 Then
    gwSize = 1
    offSetX = 0
    offSetY = 0
  Else
    gwSize = 2
    offSetX = -60
    offSetY = -50
  EndIf

  indices = Array.GetAllIndices(GW) 'returns--> 1=big;2=small
  i = indices[gwSize]

  GraphicsWindow.Width = GW[i][1]["W"]
  GraphicsWindow.Height = GW[i][1]["H"]
  GraphicsWindow.PenWidth = GW[i][1]["PW"]
  GraphicsWindow.BackgroundColor = GW[i][1]["BGC"]
  GraphicsWindow.CanResize = GW[i][1]["RS"]
  GraphicsWindow.Title = GW[i][2]["T"]
EndSub

'-----------------------------------------2nd Level Subroutine--------------------------------
Sub RefreshButton
  indices = Array.GetAllIndices(GW) 'returns--> 1=big;2=small
  i = indices[gwSize]

  GraphicsWindow.BrushColor = GW[i][1]["BC"]
  Controls.Remove(toggleGWBtn)
  toggleGWBtn = Controls.AddButton("toggle window", 10, 10)
EndSub
Copyright (c) Microsoft Corporation. All rights reserved.