Microsoft Small Basic

Program Listing: WDM914
' Cog
' Version 0.1
' Copyright © 2019 Nonki Takahashi. The MIT License.

GraphicsWindow.Title = "Cog 0.1"
Init()
bc = "Gray"
width = 80
height = 40
x = (gw - width) / 2
y = (gh - height) / 5
ox = gw / 2
oy = (gh - height) / 2
ratio = 0.4
For i = 1 To 5
AddTrapezoid()
angle = angle + 72
RotateShapesAt()
EndFor
angle = 0.5
While "True"
Program.Delay(100)
For n = 1 To 12
RotateShapesAt()
EndFor
EndWhile

Sub AddTrapezoid
' param x, y - the top left coordinate of the trapezoid
' param width - the width of the trapeziod
' param height - the height of the trapezoid
' param ratio - the x offset for the top left vertex per height
' return trap[n] - trapezoid property
GraphicsWindow.BrushColor = bc
_x = x
_y = y
_width = width
_height = height
' left triangle
x1 = height * ratio
y1 = 0
x2 = 0
y2 = _height
x3 = x1 * 2
y3 = y2
shp[1] = Shapes.AddTriangle(x1, y1, x2, y2, x3, y3)
cx[1] = x1
cy[1] = y2 / 2
Shapes.Move(shp[1], x, y)
' right triangle
x = _x + width - x3
shp[2] = Shapes.AddTriangle(x1, y1, x2, y2, x3, y3)
cx[2] = x1
cy[2] = y2 / 2
Shapes.Move(shp[2], x, y)
' middle rectangle
x = _x + x1
width = _width - x3
shp[3] = Shapes.AddRectangle(width, height)
cx[3] = width / 2
cy[3] = height / 2
Shapes.Move(shp[3], x, y)
x = _x
y = _y
width = _width
height = _height
n = n + 1
trap[n]["shp"] = shp
trap[n]["cx"] = cx
trap[n]["cy"] = cy
trap[n]["a"] = 0
EndSub

Sub RotateShapesAt
' param n - shape # to rotate
' param ox, oy - rotation center
' param angle - to rotate
shp = trap[n]["shp"]
cx = trap[n]["cx"]
cy = trap[n]["cy"]
a = trap[n]["a"] + angle
If 360 <= a Then
a = a - 360
EndIf
trap[n]["a"] = a
_angle = angle * Math.Pi / 180
_n = Array.GetItemCount(shp)
For _i = 1 To _n
x1 = Shapes.GetLeft(shp[_i]) + cx[_i]
y1 = Shapes.GetTop(shp[_i]) + cy[_i]
_x = x1 - ox
_y = y1 - oy
x2 = ox + Math.Cos(_angle) * _x - Math.Sin(_angle) * _y
y2 = oy + Math.Sin(_angle) * _x + Math.Cos(_angle) * _y
Shapes.Move(shp[_i], x2 - cx[_i], y2 - cy[_i])
Shapes.Rotate(shp[_i], a)
EndFor
EndSub

Sub Init
gw = 598
gh = 428
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
GraphicsWindow.PenWidth = 0
EndSub