Microsoft Small Basic

Program Listing:
Embed this in your website
' Rocket 0.5 (RQB683-1)
' 2012/09/09 22:31:53 Generated
' by Shapes Editor 0.5
'
' initialize shapes
Shapes_Init()
' add shapes
scale = 1
Shapes_Add()
' main code added by Nonki Takahashi
x = shX
For y = shY To 10 Step -1
  Shapes_Move()
  l = (y - 10) / 160 * 255
  color = GraphicsWindow.GetColorFromRGB(l, l, l)
  GraphicsWindow.BackgroundColor = color
EndFor
For angle = 0 To -90 Step -1
  Shapes_Rotate()
EndFor
For t = 0 To 360 * 3
  angle = -90 + 5 * Math.Sin(t * Math.Pi / 180)
  Shapes_Rotate()
EndFor
For angle = angle To 0
  Shapes_Rotate()
EndFor
x = shX
For y = shY To 170
  Shapes_Move()
  l = (y - 10) / 160 * 255
  color = GraphicsWindow.GetColorFromRGB(l, l, l)
  GraphicsWindow.BackgroundColor = color
EndFor
' main end

Sub Shapes_Init
  ' return shX, shY - current position of shapes
  ' return shape - array of shapes
  shX = 230 ' x offset
  shY = 170 ' y offset
  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 Shapes_Add
  ' param shape - array of shapes
  ' param scale
  ' return shWidth, shHeight - total size of shapes
  ' return shAngle - current angle of shapes
  Shapes_CalcWidthAndHeight()
  s = scale
  For i = 1 To nShapes
    GraphicsWindow.PenWidth = shape[i]["pw"] * s
    If shape[i]["pw"] > 0 Then
      GraphicsWindow.PenColor = shape[i]["pc"]
    EndIf
    If shape[i]["func"] = "rect" Then
      GraphicsWindow.BrushColor = shape[i]["bc"]
      x = shape[i]["x"]
      y = shape[i]["y"]
      width = shape[i]["width"]
      height = shape[i]["height"]
      shape[i]["obj"] = Shapes.AddRectangle(width * s, height * s)
      Shapes.Move(shape[i]["obj"], shX + x * s, shY + y * s)
    ElseIf shape[i]["func"] = "ell" Then
      GraphicsWindow.BrushColor = shape[i]["bc"]
      x = shape[i]["x"]
      y = shape[i]["y"]
      width = shape[i]["width"]
      height = shape[i]["height"]
      shape[i]["obj"] = Shapes.AddEllipse(width * s, height * s)
      Shapes.Move(shape[i]["obj"], shX + x * s, shY + y * s)
    ElseIf shape[i]["func"] = "tri" Then
      GraphicsWindow.BrushColor = shape[i]["bc"]
      x = shape[i]["x"]
      y = shape[i]["y"]
      x1 = shape[i]["x1"]
      y1 = shape[i]["y1"]
      x2 = shape[i]["x2"]
      y2 = shape[i]["y2"]
      x3 = shape[i]["x3"]
      y3 = shape[i]["y3"]
      shape[i]["obj"] = Shapes.AddTriangle(x1 * s, y1 * s, x2 * s, y2 * s, x3 * s, y3 * s)
      Shapes.Move(shape[i]["obj"], shX + x * s, shY + y * s)
    ElseIf shape[i]["func"] = "line" Then
      x = shape[i]["x"]
      y = shape[i]["y"]
      x1 = shape[i]["x1"]
      y1 = shape[i]["y1"]
      x2 = shape[i]["x2"]
      y2 = shape[i]["y2"]
      shape[i]["obj"] = Shapes.AddLine(x1 * s, y1 * s, x2 * s, y2 * s)
      Shapes.Move(shape[i]["obj"], shX + x * s, shY + y * s)
    EndIf
  EndFor
  shAngle = 0
EndSub

Sub Shapes_CalcWidthAndHeight
  ' return nShapes - number of shapes
  ' return shWidth, shHeight - total size of shapes
  nShapes = Array.GetItemCount(shape)
  For i = 1 To nShapes
    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_CalcRotatePos
  ' param x, y - position of a shape
  ' param width, height - size of a shape
  ' param cx, cy - center of shapes
  ' param shAngle - rotate angle
  ' return x, y - rotated position of a shape
  _cx = x + width / 2
  _cy = y + height / 2
  x = _cx - cx
  y = _cy - cy
  Math_CartesianToPolar()
  a = a + shAngle
  x = r * Math.Cos(a * Math.Pi / 180)
  y = r * Math.Sin(a * Math.Pi / 180)
  _cx = x + cx
  _cy = y + cy
  x = _cx - width / 2
  y = _cy - height / 2
EndSub

Sub Shapes_Move
  ' param shape - array of shapes
  ' param scale
  ' param x, y - position to move
  ' return shX, shY - new position of shapes
  shX = x
  shY = y
  For i = 1 To nShapes
    _x = shape[i]["x"]
    _y = shape[i]["y"]
    width = shape[i]["width"]
    height = shape[i]["height"]
    Shapes_CalcRotatePos()
    Shapes.Move(shape[i]["obj"], shX + _x * s, shY + _y * s)
  EndFor
EndSub

Sub Shapes_Remove
  ' param shape - array of shapes
  For i = 1 To nShapes
    Shapes.Remove(shape[i]["obj"])
  EndFor
EndSub

Sub Shapes_Rotate
  ' param shape - array of shapes
  ' param scale
  ' param angle
  s = scale
  shAngle = angle
  cx = shWidth / 2
  cy = shHeight / 2
  For i = 1 To nShapes
    x = shape[i]["x"]
    y = shape[i]["y"]
    width = shape[i]["width"]
    height = shape[i]["height"]
    Shapes_CalcRotatePos()
    Shapes.Move(shape[i]["obj"], shX + x * s, shY + y * s)
    Shapes.Rotate(shape[i]["obj"], shAngle)
  EndFor
EndSub

Sub Math_CartesianToPolar
  ' 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
Copyright (c) Microsoft Corporation. All rights reserved.