Microsoft Small Basic

Program Listing: RQB683-0
' Rocket 0.3 (RQB683-0)
' 2012/09/08 21:01:33 Generated
' by Shapes Editor 0.3
'
' initialize shapes
Shapes_Init()
' add shapes
scale = 1
Shapes_Add()
' following code was added by Nonki Takahashi
For angle = 0 To -90 Step -1
Shapes_Rotate()
EndFor
For t = 0 To 360 * 3
angle = -90 + 10 * Math.Sin(t * Math.Pi / 180)
Shapes_Rotate()
EndFor
For angle = angle To 0
Shapes_Rotate()
EndFor
' program end

Sub Shapes_Init
' return shX, shY - current position of shapes
' return shape - array of shapes
shX = 197 ' x offset
shY = 48 ' y offset
shape[1] = "func=tri;x=29;y=222;x1=14;y1=0;x2=0;y2=69;x3=29;y3=69;bc=#939393;pc=#000000;pw=2;"
shape[2] = "func=tri;x=189;y=222;x1=12;y1=0;x2=0;y2=69;x3=24;y3=69;bc=#939393;pc=#000000;pw=2;"
shape[3] = "func=rect;x=43;y=99;width=159;height=181;bc=#939393;pc=#000000;pw=2;"
shape[4] = "func=tri;x=112;y=222;x1=12;y1=0;x2=0;y2=69;x3=24;y3=69;bc=#939393;pc=#000000;pw=2;"
shape[5] = "func=tri;x=43;y=31;x1=78;y1=0;x2=0;y2=68;x3=157;y3=68;bc=#7A1515;pc=#000000;pw=2;"
shape[6] = "func=ell;x=72;y=111;width=99;height=99;bc=#939393;pc=#000000;pw=2;"
shape[7] = "func=ell;x=84;y=123;width=76;height=76;bc=#5ABCCD;pc=#000000;pw=2;"
shape[8] = "func=ell;x=50;y=250;width=20;height=20;bc=#939393;pc=#000000;pw=2;"
shape[9] = "func=ell;x=80;y=250;width=20;height=20;bc=#939393;pc=#000000;pw=2;"
shape[10] = "func=ell;x=145;y=250;width=20;height=20;bc=#939393;pc=#000000;pw=2;"
shape[11] = "func=ell;x=175;y=250;width=20;height=20;bc=#939393;pc=#000000;pw=2;"
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