Microsoft Small Basic

Program Listing: LCH247
' Binary Relation Rn in A={0,1}
' Copyright © 2020 Nonki Takahashi. The MIT License.
' Last update 2020-07-26

GraphicsWindow.Title = "Binary Relation Rn in A={0,1}"
Init()
While "True"
For n = 0 To 15
GraphicsWindow.Clear()
DrawSets()
buf = "R" + n + " " + symbol[n] + CR + LF + CR + LF
For a1 = 0 To 1
For a2 = 0 To 1
buf = buf + "(" + a1 + " "
buf = buf + "R" + n + " "
buf = buf + a2 + ") = "
buf = buf + R[n][Text.Append(a1, a2)] + CR + LF
If R[n][Text.Append(a1, a2)] Then
x1 = pos["a1"][a1]["x"]
y1 = pos["a1"][a1]["y"]
x2 = pos["a2"][a2]["x"]
y2 = pos["a2"][a2]["y"]
GraphicsWindow.DrawLine(x1, y1, x2, y2)
EndIf
EndFor
EndFor
GraphicsWindow.DrawText(50, 20, buf)
wait = "True"
While wait
Program.Delay(200)
EndWhile
EndFor
EndWhile

Sub DrawSets
For a = 1 To 2
x1 = pos["a" + a][0]["x"]
y1 = pos["a" + a][0]["y"]
x2 = pos["a" + a][1]["x"]
y2 = pos["a" + a][1]["y"]
GraphicsWindow.DrawText(x1 - 8, y1 - 70, "a" + a)
GraphicsWindow.DrawEllipse(x1 - 50, y1 - 50, 100, 100 + (y2 - y1))
For value = 0 To 1
x = pos["a" + a][value]["x"]
y = pos["a" + a][value]["y"]
GraphicsWindow.FillEllipse(x - _r, y - _r, 2 * _r, 2 * _r)
GraphicsWindow.DrawText(x + dx["a" + a], y - 8, value)
EndFor
EndFor
EndSub

Sub Init
CR = Text.GetCharacter(13)
LF = Text.GetCharacter(10)
' a1 0011
' a2 0101
R[0] = "00=False;01=False;10=False;11=False;"
R[1] = "00=False;01=False;10=False;11=True;"
R[2] = "00=False;01=False;10=True;11=False;"
symbol[2] = ">"
R[3] = "00=False;01=False;10=True;11=True;"
R[4] = "00=False;01=True;10=False;11=False;"
symbol[4] = "<"
R[5] = "00=False;01=True;10=False;11=True;"
R[6] = "00=False;01=True;10=True;11=False;"
symbol[6] = "≠"
R[7] = "00=False;01=True;10=True;11=True;"
R[8] = "00=True;01=False;10=False;11=False;"
R[9] = "00=True;01=False;10=False;11=True;"
symbol[9] = "="
R[10] = "00=True;01=False;10=True;11=False;"
R[11] = "00=True;01=False;10=True;11=True;"
symbol[11] = "≧"
R[12] = "00=True;01=True;10=False;11=False;"
R[13] = "00=True;01=True;10=False;11=True;"
symbol[13] = "≦"
R[14] = "00=True;01=True;10=True;11=False;"
R[15] = "00=True;01=True;10=True;11=True;"
pos["a1"][0] = "x=250;y=180;"
pos["a1"][1] = "x=250;y=330;"
pos["a2"][0] = "x=400;y=180;"
pos["a2"][1] = "x=400;y=330;"
dx["a1"] = -20
dx["a2"] = 10
_r = 4
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.KeyDown = OnKeyDown
EndSub

Sub OnkeyDown
wait = "False"
EndSub