Microsoft Small Basic

Program Listing:
Embed this in your website
' Sound sample
' Program by Nonki Takahashi
' Mickey designed by mahreen miangul

SB_Workaround()
Shapes_Init_Mickey()
' add shapes
scale = 1
angle = 0
iMin = 1
iMax = 15
Shapes_Add()
GraphicsWindow.Title = "Click!"
url = "http://www.nonkit.com/smallbasic.files/Hello.m4a"
GraphicsWindow.MouseDown = OnMouseDown
While "True"
  If mouseDown Then
    GraphicsWindow.BackgroundColor = "Yellow"
    Sound.Play(url)
    Program.Delay(2000)
    Sound.Stop(url)
    GraphicsWindow.BackgroundColor = "White"
    mouseDown = "False"
  Else
    Program.Delay(200)
  EndIf
EndWhile

Sub OnMouseDown
  mouseDown = "True"
EndSub

Sub SB_RotateWorkaround
  ' Small Basic | Rotate workaround for Silverlight
  ' param x, y - original coordinate
  ' param alpha - angle [radian]
  ' returns x, y - workaround coordinate
  If shape[i]["func"] = "tri" Then
    x1 = -Math.Floor(shape[i]["x3"] / 2)
    y1 = -Math.Floor(shape[i]["y3"] / 2)
  ElseIf shape[i]["func"] = "line" Then
    x1 = -Math.Floor(Math.Abs(shape[i]["x1"] - shape[i]["x2"]) / 2)
    y1 = -Math.Floor(Math.Abs(shape[i]["y1"] - shape[i]["y2"]) / 2)
  EndIf
  ox = x - x1
  oy = y - y1
  x = x1 * Math.Cos(alpha) - y1 * Math.Sin(alpha) + ox
  y = x1 * Math.Sin(alpha) + y1 * Math.Cos(alpha) + oy
EndSub

Sub SB_Workaround
  ' Small Basic | Workaround for Silverlight
  ' returns silverlight - "True" if in remote
  color = GraphicsWindow.GetPixel(0, 0)
  If Text.GetLength(color) > 7 Then
    silverlight = "True"
    msWait = 300
  Else
    silverlight = "False"
  EndIf
EndSub

Sub Shapes_Add
  ' Shapes | add shapes as shapes data
  ' param iMin, iMax - shape indices to add
  ' param shape - array of shapes
  ' param scale - 1 if same scale
  ' return shWidth, shHeight - total size of shapes
  ' return shAngle - current angle of shapes
  Stack.PushValue("local", i)
  Stack.PushValue("local", x)
  Stack.PushValue("local", y)
  Shapes_CalcWidthAndHeight()
  s = scale
  For i = iMin To iMax
    GraphicsWindow.PenWidth = shape[i]["pw"] * s
    If shape[i]["pw"] > 0 Then
      GraphicsWindow.PenColor = shape[i]["pc"]
    EndIf
    If Text.IsSubText("rect|ell|tri|text", shape[i]["func"]) Then
      GraphicsWindow.BrushColor = shape[i]["bc"]
    EndIf
    If shape[i]["func"] = "rect" Then
      shape[i]["obj"] = Shapes.AddRectangle(shape[i]["width"] * s, shape[i]["height"] * s)
    ElseIf shape[i]["func"] = "ell" Then
      shape[i]["obj"] = Shapes.AddEllipse(shape[i]["width"] * s, shape[i]["height"] * s)
    ElseIf shape[i]["func"] = "tri" Then
      shape[i]["obj"] = Shapes.AddTriangle(shape[i]["x1"] * s, shape[i]["y1"] * s, shape[i]["x2"] * s, shape[i]["y2"] * s, shape[i]["x3"] * s, shape[i]["y3"] * s)
    ElseIf shape[i]["func"] = "line" Then
      shape[i]["obj"] = Shapes.AddLine(shape[i]["x1"] * s, shape[i]["y1"] * s, shape[i]["x2"] * s, shape[i]["y2"] * s)
    ElseIf shape[i]["func"] = "text" Then
      If silverlight Then
        fs = Math.Floor(shape[i]["fs"] * 0.9)
      Else
        fs = shape[i]["fs"]
      EndIf
      GraphicsWindow.FontSize = fs * s
      GraphicsWindow.FontName = shape[i]["fn"]
      shape[i]["obj"] = Shapes.AddText(shape[i]["text"])
    EndIf
    x = shape[i]["x"]
    y = shape[i]["y"]
    shape[i]["rx"] = x
    shape[i]["ry"] = y
    If silverlight And Text.IsSubText("tri|line", shape[i]["func"]) Then
      alpha = Math.GetRadians(shape[i]["angle"])
      SB_RotateWorkaround()
      shape[i]["wx"] = x
      shape[i]["wy"] = y
    EndIf
    Shapes.Move(shape[i]["obj"], shX + x * s, shY + y * s)
    If Text.IsSubText("rect|ell|tri|text", shape[i]["func"]) And shape[i]["angle"] <> 0 Then
      Shapes.Rotate(shape[i]["obj"], shape[i]["angle"])
    EndIf
  EndFor
  shAngle = 0
  y = Stack.PopValue("local")
  x = Stack.PopValue("local")
  i = Stack.PopValue("local")
EndSub

Sub Shapes_CalcWidthAndHeight
  ' Shapes | Calculate total width and height of shapes
  ' param iMin, iMax - shape indices to add
  ' return shWidth, shHeight - total size of shapes
  For i = iMin To iMax
    If shape[i]["func"] = "tri" Or shape[i]["func"] = "line" Then
      xmin = shape[i]["x1"]
      xmax = shape[i]["x1"]
      ymin = shape[i]["y1"]
      ymax = shape[i]["y1"]
      If shape[i]["x2"] < xmin Then
        xmin = shape[i]["x2"]
      EndIf
      If xmax < shape[i]["x2"] Then
        xmax = shape[i]["x2"]
      EndIf
      If shape[i]["y2"] < ymin Then
        ymin = shape[i]["y2"]
      EndIf
      If ymax < shape[i]["y2"] Then
        ymax = shape[i]["y2"]
      EndIf
      If shape[i]["func"] = "tri" Then
        If shape[i]["x3"] < xmin Then
          xmin = shape[i]["x3"]
        EndIf
        If xmax < shape[i]["x3"] Then
          xmax = shape[i]["x3"]
        EndIf
        If shape[i]["y3"] < ymin Then
          ymin = shape[i]["y3"]
        EndIf
        If ymax < shape[i]["y3"] Then
          ymax = shape[i]["y3"]
        EndIf
      EndIf
      shape[i]["width"] = xmax - xmin
      shape[i]["height"] = ymax - ymin
    EndIf
    If i = 1 Then
      shWidth = shape[i]["x"] + shape[i]["width"]
      shHeight = shape[i]["y"] + shape[i]["height"]
    Else
      If shWidth < shape[i]["x"] + shape[i]["width"] Then
        shWidth = shape[i]["x"] + shape[i]["width"]
      EndIf
      If shHeight < shape[i]["y"] + shape[i]["height"] Then
        shHeight = shape[i]["y"] + shape[i]["height"]
      EndIf
    EndIf
  EndFor
EndSub

Sub Shapes_Init_Mickey
  ' Shapes | Initialize shapes data
  ' return shX, shY - current position of shapes
  ' return shape - array of shapes
  shX = 100   ' x offset
  shY = -180  ' y offset
  shape = ""
  shape[1] = "func=ell;x=130;y=330;width=180;height=180;angle=0;bc=black;pc=black;pw=0;"
  shape[2] = "func=ell;x=110;y=275;width=80;height=80;angle=0;bc=black;pc=black;pw=0;"
  shape[3] = "func=ell;x=250;y=275;width=80;height=80;angle=0;bc=black;pc=black;pw=0;"
  shape[4] = "func=ell;x=155;y=340;width=65;height=85;angle=0;bc=PeachPuff;pc=black;pw=0;"
  shape[5] = "func=ell;x=218;y=340;width=65;height=85;angle=0;bc=PeachPuff;pc=black;pw=0;"
  shape[6] = "func=ell;x=133;y=410;width=175;height=75;angle=0;bc=PeachPuff;pc=black;pw=0;"
  shape[7] = "func=ell;x=152;y=422;width=140;height=88;angle=0;bc=PeachPuff;pc=black;pw=0;"
  shape[8] = "func=ell;x=190;y=360;width=18;height=50;angle=0;bc=white;pc=black;pw=0;"
  shape[9] = "func=ell;x=218;y=360;width=18;height=50;angle=0;bc=white;pc=black;pw=0;"
  shape[10] = "func=ell;x=193;y=380;width=10;height=30;angle=0;bc=black;pc=black;pw=0;"
  shape[11] = "func=ell;x=223;y=380;width=10;height=30;angle=0;bc=black;pc=black;pw=0;"
  shape[12] = "func=ell;x=190;y=415;width=50;height=30;angle=0;bc=black;pc=black;pw=0;"
  shape[13] = "func=ell;x=180;y=463;width=77;height=50;angle=0;bc=black;pc=black;pw=0;"
  shape[14] = "func=ell;x=205;y=495;width=30;height=15;angle=0;bc=red;pc=black;pw=0;"
  shape[15] = "func=ell;x=218;y=495;width=3;height=10;angle=0;bc=black;pc=black;pw=0;"
EndSub
Copyright (c) Microsoft Corporation. All rights reserved.