Sub DrawDice
edge = ""
f = ""
For j = 1 To 6
x = face[j]["x"]
y = face[j]["y"]
z = face[j]["z"]
Mapping()
If "1E-5" < z Then
' face
l = Math.Floor(z * 44) + 211
gray = GraphicsWindow.GetColorFromRGB(l, l, l)
GraphicsWindow.BrushColor = gray
GraphicsWindow.PenColor = gray
p1 = Text.GetSubText(face[j][1], 1, 1)
p2 = Text.GetSubText(face[j][1], 2, 1)
p3 = Text.GetSubText(face[j][2], 2, 1)
FillTriangle()
GraphicsWindow.DrawLine(x1, y1, x3, y3)
p1 = Text.GetSubText(face[j][3], 1, 1)
p2 = Text.GetSubText(face[j][3], 2, 1)
p3 = Text.GetSubText(face[j][4], 2, 1)
FillTriangle()
For i = 1 To j
' dots
GraphicsWindow.BrushColor = d[j][i]["color"]
x = d[j][i]["x"]
y = d[j][i]["y"]
z = d[j][i]["z"]
Mapping()
GraphicsWindow.FillEllipse(x - pw / 2, y - pw / 2 , pw, pw)
EndFor
n = 4
For i = 1 To 4
' edges
edge[face[j][i]] = 1
EndFor
EndIf
n = Array.GetItemCount(edge)
iEdge = Array.GetAllIndices(edge)
GraphicsWindow.PenColor = "LightGray"
For i = 1 To n
v1 = Text.GetSubText(iEdge[i], 1, 1)
v2 = Text.GetSubText(iEdge[i], 2, 1)
x = v[v1]["x"]
y = v[v1]["y"]
z = v[v1]["z"]
Mapping()
x1 = x
y1 = y
x = v[v2]["x"]
y = v[v2]["y"]
z = v[v2]["z"]
Mapping()
x2 = x
y2 = y
GraphicsWindow.DrawLine(x1, y1, x2, y2)
EndFor
EndFor
EndSub
Sub FillTriangle
x = v[p1]["x"]
y = v[p1]["y"]
z = v[p1]["z"]
Mapping()
x1 = x
y1 = y
x = v[p2]["x"]
y = v[p2]["y"]
z = v[p2]["z"]
Mapping()
x2 = x
y2 = y
x = v[p3]["x"]
y = v[p3]["y"]
z = v[p3]["z"]
Mapping()
x3 = x
y3 = y
GraphicsWindow.FillTriangle(x1, y1, x2, y2, x3, y3)
EndSub
Sub Mapping
' param x, y, z - point to map
' param a - angle around x axis
' param b - angle around y axis
' param c - angle around z axis
_a = Math.GetRadians(a)
_y = y
_z = z
y = Math.Cos(_a) * _y - Math.Sin(_a) * _z
z = Math.Sin(_a) * _y + Math.Cos(_a) * _z
_b = Math.GetRadians(b)
_z = z
_x = x
z = Math.Cos(_b) * _z - Math.Sin(_b) * _x
x = Math.Sin(_b) * _z + Math.Cos(_b) * _x
_c = Math.GetRadians(c)
_x = x
_y = y
x = Math.Cos(_c) * _x - Math.Sin(_c) * _y
y = Math.Sin(_c) * _x + Math.Cos(_c) * _y
x = ox + x * scale
y = oy - y * scale
EndSub