Microsoft Small Basic

Program Listing: CDG636
' Pictionary - Remainder
' Version 1.3.0
' Copyright © 2020 Nonki Takahashi. The MIT License.
' Last update 2020-04-22
'
Not = "False=True;True=False;"
GraphicsWindow.Title = "Pictionary"
Form()
num1 = 31 ' devidend
num2 = 7 ' devisor
Div()
GraphicsWindow.PenWidth = 4
GraphicsWindow.PenColor = "#CC0000"
GraphicsWindow.DrawEllipse(xo + 130, yo + 190, 60, 60)
x = 330
y = 50
GraphicsWindow.BrushColor = "#CCCCCC"
For i = 1 To num1
GraphicsWindow.FillEllipse(x, y, 20, 20)
If Math.Remainder(i, num2) = 0 Then
y = 50
x = x + 40
Else
y = y + 40
EndIf
EndFor
GraphicsWindow.DrawRectangle(330 + (5 - 1) * 40 - 5, 50 - 10, 30, 3 * 40)
Caption()

Sub Caption
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.FontSize = 50
GraphicsWindow.FontName = "Trebuchet MS"
GraphicsWindow.DrawText(325, 358, "Remainder")
EndSub

Sub Div
len1 = Text.GetLength(num1)
len2 = Text.GetLength(num2)
fw = fs * 0.6
stp = "write the dividend"
Next()
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.DrawText(xo + fw * (len2 + 2), yo + fs, num1)
stp = "draw a line and an arc"
Next()
GraphicsWindow.PenWidth = fs / 10
GraphicsWindow.DrawLine(xo + fw * (len2 + 1), yo + fs * 1.08, xo + fw * (len1 + len2 + 2), yo + fs * 1.08)
GraphicsWindow.DrawText(xo + fw * (len2 + 1), yo + fs * (1 - 0.15), ")")
stp = "write the divisor"
Next()
GraphicsWindow.DrawText(xo + fw, yo + fs, num2)
n = len1 - len2 + 1
j = 0
For i = 1 To n
stp = "focus the divisor and a part of the dividend"
Next()
GraphicsWindow.PenWidth = 0
GraphicsWindow.BrushColor = rectColor
rect2 = Shapes.AddRectangle(fw * len2, fs)
Shapes.Move(rect2, xo + fw, yo + fs)
If i = 1 Then
n1 = Text.GetSubText(num1, 1, len2)
EndIf
If n1 < num2 Then
n1 = Text.Append(n1, Text.GetSubText(num1, i + 1, 1))
i = i + 1
EndIf
If 1 < i Then
rect1 = Shapes.AddRectangle(fw * (len2 + 1), fs)
Else
rect1 = Shapes.AddRectangle(fw * len2, fs)
EndIf
j = j + 1
Shapes.Move(rect1, xo + fw * (len2 + 2), yo + fs * (2 * (j - 1) + 1))
stp = "make a quotient"
Next()
If num2 <= n1 Then
q = Math.Floor(n1 / num2)
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.DrawText(xo + fw * (len2 + i + 1), yo, q)
EndIf
stp = "multiply the quotient and the divisor"
Next()
Shapes.Remove(rect1)
GraphicsWindow.BrushColor = rectColor
rectQ = Shapes.AddRectangle(fw * len2, fs)
Shapes.Move(rectQ, xo + fw * (len2 + i + 1), yo)
m = q * num2
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.DrawText(xo + fw * (len2 + 2), yo + fs * (2 * (j - 1) + 2), m)
stp = "draw a line"
Next()
GraphicsWindow.PenWidth = fs / 10
y = yo + fs * (2 * (j - 1) + 3.08)
GraphicsWindow.DrawLine(xo + fw * (len2 + 2), y, xo + fw * (2 * len2 + 3), y)
Shapes.Remove(rect2)
Shapes.Remove(rectQ)
stp = "subtract the product from the part of the dividend"
Next()
GraphicsWindow.PenWidth = 0
GraphicsWindow.BrushColor = rectColor
rectD = Shapes.AddRectangle(fw * (len2 + i - 1), fs)
Shapes.Move(rectD, xo + fw * (len2 + 2), y - fs * 2)
rectP = Shapes.AddRectangle(fw * (len2 + i - 1), fs)
Shapes.Move(rectP, xo + fw * (len2 + 2), y - fs)
r = n1 - m
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.DrawText(xo + fw * (len2 + i + 1), y, r)
stp = "remove focus rectangles"
Next()
Shapes.Remove(rectD)
Shapes.Remove(rectP)
stp = "lower the next part of the dividend"
Next()
If i < n Then
n1 = Text.GetSubText(num1, i + 1, 1)
GraphicsWindow.DrawText(xo + fw * (len2 + i + 2), y, n1)
n1 = Text.Append(r, n1)
EndIf
EndFor
EndSub

Sub Form
gw = 598
gh = 428
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
GraphicsWindow.PenWidth = 0
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.FontName = "Consolas"
fs = 60
GraphicsWindow.FontSize = fs
xo = 50
yo = 50
rectColor = "#11000000"
EndSub

Sub Next
Program.Delay(100)
EndSub