Microsoft Small Basic

Program Listing: CQK137
' Balance Scale
' Version 0.1a
' Copyright © 2017 Nonki Takahashi. The MIT License.

GraphicsWindow.Title = "Balance Scale"
Init()
Move()

Sub Init
gw = 598
gh = 428
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
GraphicsWindow.PenWidth = 0
GraphicsWindow.BrushColor = "Black"
width = 160
height = 16
x = (gw - width) / 2
y2 = gh - 50 - height
GraphicsWindow.FillRectangle(x, y2, width, height)
bw = 360
bh = 16
x = (gw - bw) / 2
by = 100
beam = Shapes.AddRectangle(bw, bh)
Shapes.Move(beam, x, by)
width = 16
x = (gw - width) / 2
y = by + 32
height = y2 - y
GraphicsWindow.FillRectangle(x, y, width, height)
GraphicsWindow.FillTriangle(x, y, x + width, y, x + width / 2, y - 24)
GraphicsWindow.PenWidth = 2
GraphicsWindow.BrushColor = "Transparent"
width = 160
height = 200
pan[1] = Shapes.AddTriangle(0, 0, -width / 2, height, width / 2, height)
pan[2] = Shapes.AddTriangle(0, 0, -width / 2, height, width / 2, height)
EndSub

Sub Move
t = 0
a0 = 5
While "True"
t = t + 1
a = a0 * Math.Sin(Math.GetRadians(t))
x[1] = gw / 2 - bw / 2 * Math.Cos(Math.GetRadians(a))
y[1] = by + bh / 2 - bw / 2 * Math.Sin(Math.GetRadians(a))
x[2] = gw / 2 + bw / 2 * Math.Cos(Math.GetRadians(a))
y[2] = by + bh / 2 + bw / 2 * Math.Sin(Math.GetRadians(a))
Shapes.Rotate(beam, a)
Shapes.Move(pan[1], x[1], y[1])
Shapes.Move(pan[2], x[2], y[2])
If t = 360 Then
t = 0
EndIf
a0 = a0 * 0.998
Program.Delay(10)
EndWhile
EndSub