Microsoft Small Basic

Program Listing: MMF211
' Flip Sample
' Version 0.1a
' Copyright © 2016 Nonki Takahashi. The MIT License.

GraphicsWindow.Title = "Flip 0.1a"
Shapes_Init()
Shapes_Add()
While "True"
Shapes_Flip()
Program.Delay(1000)
EndWhile

Sub Shapes_Init
group[1] = "x=300;y=200;name=Magenta Fish;"
shape[1] = "func=rect;x=45;y=15;width=20;height=10;bc=#33000000;pw=0;"
shape[1] = "func=tri;x=40;y=0;width=20;height=40;angle=-90;bc=#33000000;pw=0;"
shape[2] = "func=ell;x=20;y=5;width=20;height=10;angle=-10;bc=#33000000;pw=0;"
shape[3] = "func=ell;x=0;y=10;width=50;height=20;bc=Magenta;pw=0;"
shape[4] = "func=ell;x=5;y=15;width=10;height=10;bc=Black;pw=2;pc=White;"
EndSub

Sub Shapes_Add
grp = group[1]
x = grp["x"]
y = grp["y"]
n = Array.GetItemCount(shape)
For i = 1 To n
shp = shape[i]
GraphicsWindow.BrushColor = shp["bc"]
GraphicsWindow.PenWidth = shp["pw"]
If 0 < shp["pw"] Then
GraphicsWindow.PenColor = shp["pc"]
EndIf
If shp["func"] = "rect" Then
shp["obj"] = Shapes.AddRectangle(shp["width"], shp["height"])
ElseIf shp["func"] = "ell" Then
shp["obj"] = Shapes.AddEllipse(shp["width"], shp["height"])
ElseIf shp["func"] = "tri" Then
shp["obj"] = Shapes.AddTriangle(0, shp["height"], shp["width"] / 2, 0, shp["width"], shp["height"])
EndIf
If i = 1 Then
xmin = shp["x"]
xmax = shp["x"] + shp["width"]
ymin = shp["y"]
ymax = shp["y"] + shp["height"]
Else
If shp["x"] < xmin Then
xmin = shp["x"]
EndIf
If xmax < shp["x"] + shp["width"] Then
xmax = shp["x"] + shp["width"]
EndIf
If shp["y"] < ymin Then
ymin = shp["y"]
EndIf
If ymax < shp["y"] + shp["height"] Then
ymax = shp["y"] + shp["height"]
EndIf
EndIf
If shp["angle"] <> 0 Then
Shapes.Rotate(shp["obj"], shp["angle"])
EndIf
Shapes.Move(shp["obj"], x + shp["x"], y + shp["y"])
shape[i] = shp
EndFor
cx = Math.Floor((xmin + xmax) / 2 * 100) / 100
grp["cx"] = cx
group[1] = grp
EndSub

Sub Shapes_Flip
grp = group[1]
gx = grp["x"]
gy = grp["y"]
For angle = 20 To 180 Step 20
_a = Math.GetRadians(angle)
scaleX = Math.Cos(_a)
For i = 1 To n
shp = shape[i]
Shapes.Zoom(shp["obj"], Math.Abs(scaleX), 1)
cx = shp["x"] + shp["width"] / 2
cx = (cx - grp["cx"]) * scaleX + grp["cx"]
Shapes.Move(shp["obj"], cx - shp["width"] / 2 + gx, shp["y"] + gy)
If angle = 100 And shp["angle"] <> 0 Then
shp["angle"] = -shp["angle"]
Shapes.Rotate(shp["obj"], shp["angle"])
shape[i] = shp
EndIf
If angle = 180 Then
shp["x"] = Math.Floor((cx - shp["width"] / 2) * 100) / 100
shape[i] = shp
EndIf
EndFor
Program.Delay(100)
EndFor
EndSub