Microsoft Small Basic

Program Listing:
Embed this in your website
' Rocket 0.51 (RQB683-3)
' 10/07/2013 16:10:22 Shapes generated by Shapes 1.5b
'
GraphicsWindow.Title = "Rocket 0.51"
' initialize shapes
SB_Workaround()
Stars_Add()
Shapes_Init()
' add shapes
scale = 1
angle = 0
iMin = 1
iMax = 15
Shapes_Add()
' main code added by Nonki Takahashi
x = shX
dx = 0
dy = 5
For y = shY To 10 Step -2
  Shapes_Move()
  Stars_Scroll()
  l = (y - 10) / 160 * 255 * 2
  If 255 < l Then
    color = GraphicsWindow.GetColorFromRGB(l - 255, l - 255, 255)
  Else
    color = GraphicsWindow.GetColorFromRGB(0, 0, l)
  EndIf
  GraphicsWindow.BackgroundColor = color
EndFor
For angle = 0 To -90 Step -2
  Shapes_Rotate()
  dx = -5 * Math.Sin(Math.GetRadians(angle))
  dy = 5 * Math.Cos(Math.GetRadians(angle))
  Stars_Scroll()
EndFor
dx = 5
dy = 0
For t = 0 To 360 * 3 Step 8
  angle = -90 + 5 * Math.Sin(t * Math.Pi / 180)
  Shapes_Rotate()
  Stars_Scroll()
EndFor
For angle = angle To 0 Step 2
  Shapes_Rotate()
  dx = -5 * Math.Sin(Math.GetRadians(angle))
  dy = -5 * Math.Cos(Math.GetRadians(angle))
  Stars_Scroll()
EndFor
x = shX
dx = 0
dy = -5
For y = shY To 170 Step 2
  Shapes_Move()
  Stars_Scroll()
  l = (y - 10) / 160 * 255 * 2
  If 255 < l Then
    color = GraphicsWindow.GetColorFromRGB(l - 255, l - 255, 255)
  Else
    color = GraphicsWindow.GetColorFromRGB(0, 0, l)
  EndIf
  GraphicsWindow.BackgroundColor = color
EndFor
' main end
Sub Stars_Add
  nStars = 50
  gw = GraphicsWindow.Width
  gh = GraphicsWindow.Height
  GraphicsWindow.PenWidth = 0
  GraphicsWindow.BrushColor = "White"
  For i = 1 To nStars
    star["x" + i] = Math.GetRandomNumber(gw)
    star["y" + i] = Math.GetRandomNumber(gh)
    star["o" + i] = Shapes.AddEllipse(2, 2)
    Shapes.Move(star["o" + i], star["x" + i], star["y" + i])
  EndFor
EndSub
Sub Stars_Scroll
  For i = 1 To nStars
    star["x" + i] = star["x" + i] + dx
    If star["x" + i] < 0 Then
      star["x" + i] = star["x" + i] + gw
    ElseIf gw <= star["x" + i] Then
      star["x" + i] = star["x" + i] - gw
    EndIf
    star["y" + i] = star["y" + i] + dy
    If star["y" + i] < 0 Then
      star["y" + i] = star["y" + i] + gh
    ElseIf gh <= star["y" + i] Then
      star["y" + i] = star["y" + i] - gh
    EndIf
    Shapes.Move(star["o" + i], star["x" + i], star["y" + i])
  EndFor
EndSub
Sub Shapes_Init
  ' Shapes | Initialize shapes data
  ' return shX, shY - current position of shapes
  ' return shape - array of shapes
  shX = 230 ' x offset
  shY = 170 ' y offset
  shape = ""
  shape[1] = "func=tri;x=22;y=0;x1=70;y1=0;x2=0;y2=96;x3=140;y3=96;bc=#752424;pc=#000000;pw=2;"
  shape[2] = "func=tri;x=0;y=194;x1=21;y1=0;x2=0;y2=78;x3=42;y3=78;bc=#6E6E6E;pc=#000000;pw=2;"
  shape[3] = "func=tri;x=142;y=193;x1=20;y1=0;x2=0;y2=80;x3=41;y3=80;bc=#6E6E6E;pc=#000000;pw=2;"
  shape[4] = "func=tri;x=52;y=189;x1=41;y1=0;x2=0;y2=70;x3=82;y3=70;bc=#1F1F1F;pc=#000000;pw=2;"
  shape[5] = "func=rect;x=21;y=96;width=143;height=144;bc=#6E6E6E;pc=#000000;pw=2;"
  shape[6] = "func=tri;x=73;y=192;x1=20;y1=0;x2=0;y2=81;x3=41;y3=81;bc=#6E6E6E;pc=#000000;pw=2;"
  shape[7] = "func=ell;x=51;y=101;width=84;height=88;bc=#6E6E6E;pc=#000000;pw=2;"
  shape[8] = "func=ell;x=59;y=110;width=68;height=71;bc=#217DBB;pc=#000000;pw=2;"
  shape[9] = "func=ell;x=29;y=211;width=16;height=18;bc=#6E6E6E;pc=#000000;pw=2;"
  shape[10] = "func=ell;x=56;y=213;width=16;height=17;bc=#6E6E6E;pc=#000000;pw=2;"
  shape[11] = "func=ell;x=115;y=213;width=15;height=16;bc=#6E6E6E;pc=#000000;pw=2;"
  shape[12] = "func=ell;x=140;y=213;width=12;height=15;bc=#6E6E6E;pc=#000000;pw=2;"
  shape[13] = "func=ell;x=65;y=278;width=57;height=146;bc=#FF0F0F;pw=0;"
  shape[14] = "func=ell;x=76;y=286;width=36;height=102;bc=#FF930F;pw=0;"
  shape[15] = "func=ell;x=85;y=291;width=18;height=50;bc=#FFEF0F;pw=0;"
EndSub
Sub Math_CartesianToPolar
  ' Math | convert cartesian coodinate to polar coordinate
  ' param x, y - cartesian coordinate
  ' return r, a - polar coordinate
  r = Math.SquareRoot(x * x + y * y)
  If x = 0 And y > 0 Then
    a = 90 ' [degree]
  ElseIf x = 0 And y < 0 Then
    a = -90
  Else
    a = Math.ArcTan(y / x) * 180 / Math.Pi
  EndIf
  If x < 0 Then
    a = a + 180
  ElseIf x > 0 And y < 0 Then
    a = a + 360
  EndIf
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)
  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
    If silverlight And shape[i]["func"] = "tri" Then
      alpha = Math.GetRadians(shape[i]["angle"])
      x1 = -Math.Floor(shape[i]["x3"] / 2)
      y1 = -Math.Floor(shape[i]["y3"] / 2)
      ox = shape[i]["x"] - x1
      oy = shape[i]["y"] - y1
      r = Math.SquareRoot(x1 * x1 + y1 * y1)
      x = x1 * Math.Cos(alpha) - y1 * Math.Sin(alpha) + ox
      y = x1 * Math.Sin(alpha) + y1 * Math.Cos(alpha) + oy
      Shapes.Move(shape[i]["obj"], shX + x * s, shY + y * s)
    Else
      Shapes.Move(shape[i]["obj"], shX + shape[i]["x"] * s, shY + shape[i]["y"] * s)
    EndIf
    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
    shape[i]["rx"] = shape[i]["x"]
    shape[i]["ry"] = shape[i]["y"]
  EndFor
  shAngle = 0
  i = Stack.PopValue("local")
EndSub
Sub Shapes_CalcRotatePos
  ' Shapes | Calculate position for rotated shape
  ' param["x"], param["y"] - position of a shape
  ' param["width"], param["height"] - size of a shape
  ' param ["cx"], param["cy"] - center of rotation
  ' param ["angle"] - rotate angle
  ' return x, y - rotated position of a shape
  _cx = param["x"] + param["width"] / 2
  _cy = param["y"] + param["height"] / 2
  x = _cx - param["cx"]
  y = _cy - param["cy"]
  Math_CartesianToPolar()
  a = a + param["angle"]
  x = r * Math.Cos(a * Math.Pi / 180)
  y = r * Math.Sin(a * Math.Pi / 180)
  _cx = x + param["cx"]
  _cy = y + param["cy"]
  x = _cx - param["width"] / 2
  y = _cy - param["height"] / 2
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_Move
  ' Shapes | Move shapes
  ' param iMin, iMax - shape indices to add
  ' param shape - array of shapes
  ' param scale - to zoom
  ' param x, y - position to move
  ' return shX, shY - new position of shapes
  Stack.PushValue("local", i)
  s = scale
  shX = x
  shY = y
  For i = iMin To iMax
    _x = shape[i]["rx"]
    _y = shape[i]["ry"]
    Shapes.Move(shape[i]["obj"], shX + _x * s, shY + _y * s)
  EndFor
  i = Stack.PopValue("local")
EndSub
Sub Shapes_Remove
  ' Shapes | Remove shapes
  ' param iMin, iMax - shapes indices to remove
  ' param shape - array of shapes
  Stack.PushValue("local", i)
  For i = iMin To iMax
    Shapes.Remove(shape[i]["obj"])
  EndFor
  i = Stack.PopValue("local")
EndSub
Sub Shapes_Rotate
  ' Shapes | Rotate shapes
  ' param iMin, iMax - shapes indices to rotate
  ' param shape - array of shapes
  ' param scale - to zoom
  ' param angle - to rotate
  Stack.PushValue("local", i)
  Stack.PushValue("local", x)
  Stack.PushValue("local", y)
  s = scale
  param["angle"] = angle
  param["cx"] = shWidth / 2
  param["cy"] = shHeight / 2
  For i = iMin To iMax
    param["x"] = shape[i]["x"]
    param["y"] = shape[i]["y"]
    param["width"] = shape[i]["width"]
    param["height"] = shape[i]["height"]
    Shapes_CalcRotatePos()
    If silverlight And Text.IsSubText("tri|line", shape[i]["func"]) Then
      alpha = Math.GetRadians(angle + shape[i]["angle"])
      SB_RotateWorkAround()
    EndIf
    shape[i]["rx"] = x
    shape[i]["ry"] = y
    Shapes.Move(shape[i]["obj"], shX + x * s, shY + y * s)
    Shapes.Rotate(shape[i]["obj"], angle + shape[i]["angle"])
  EndFor
  y = Stack.PopValue("local")
  x = Stack.PopValue("local")
  i = Stack.PopValue("local")
EndSub
Copyright (c) Microsoft Corporation. All rights reserved.