GraphicsWindow.Title = "Tokyo 2020 Games Flag"
SB_Workaround()
Init()
Shapes_Init_Olympic()
name = "Olymic"
scale = 1 / 2.3
Group_Add()
x = 120
y = 80
i = nGroup
Group_Move()
OlympicFlag()
Shapes_Init_Paralympic()
name = "Paralymic"
Group_Add()
x = 470
y = 80
i = nGroup
Group_Move()
ParalympicFlag()
Sub Init
Not = "False=True;True=False;"
gw = 810
gh = 540
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
EndSub
Sub OlympicFlag
lx = 110
ty = 300
oh = 160
ow = oh / 2 * 3
GraphicsWindow.DrawRectangle(lx, ty, ow, oh)
w = oh / 30
r = oh / 6 - w / 2
GraphicsWindow.PenWidth = w
color = "1=#0067C0;2=#FFD400;3=#000000;4=#008000;5=#ED1A3D;"
x[1] = ow / 2 - 3 * r - 2 * w
y[1] = ow / 4 + w / 2
x[2] = ow / 2 - 2 * r - w
y[2] = ow / 4 + w / 2 + r
x[3] = ow / 2 - r
y[3] = ow / 4 + w / 2
x[4] = ow / 2 + w
y[4] = ow / 4 + w / 2 + r
x[5] = ow / 2 + r + 2 * w
y[5] = ow / 4 + w / 2
GraphicsWindow.PenWidth = 0
For a = -315 To 135
If a = 45 Then
a = 90
EndIf
_a = Math.GetRadians(a)
For i = 1 To 5
GraphicsWindow.BrushColor = color[i]
cx = x[i] + r
cy = y[i] + r
px = lx + cx + r * Math.Cos(_a) - w / 2
py = ty + cy + r * Math.Sin(_a) - w / 2
GraphicsWindow.FillEllipse(px, py, w, w)
EndFor
EndFor
EndSub
Sub CalcMidPoint
' param k - 0..1
x[param[3]] = x[param[1]] + k * (x[param[2]] - x[param[1]])
y[param[3]] = y[param[1]] + k * (y[param[2]] - y[param[1]])
EndSub
Sub GetPoints
GraphicsWindow.PenWidth = 2
For i = 1 To Array.GetItemCount(cubic[j])
p = cubic[j][i]
c = Text.GetIndexOf(p, ",")
x[i] = Text.GetSubText(p, 1, c - 1)
y[i] = Text.GetSubTextToEnd(p, c + 1)
If Text.StartsWith(x[i], "r") Then
x[i] = Text.GetSubTextToEnd(x[i], 2)
x[i] = xLast + x[i]
y[i] = yLast + y[i]
EndIf
If Math.Remainder(i, 3) = 1 Then
xLast = x[i]
yLast = y[i]
EndIf
x[i] = x[i] * scale + ox
y[i] = y[i] * scale + oy
EndFor
EndSub
Sub Group_Add
' Group | add shapes to a group
' param name - group name
' param shX, shY, origin of shape array
' param scale - scale of group
' param shape[] - shape array
' param nGroup - number of group
' return nGroup - updated number of group
' return group - group array
Stack.PushValue("local", i)
Stack.PushValue("local", x)
Stack.PushValue("local", y)
nGroup = nGroup + 1
grp = ""
grp["name"] = name
grp["x"] = shX
grp["y"] = shY
grp["angle"] = 0
grp["dir"] = 1
Shapes_CalcWidthAndHeight()
grp["width"] = shWidth
grp["cx"] = shWidth / 2
grp["height"] = shHeight
s = scale
grp["scale"] = s
For i = 1 To Array.GetItemCount(shape)
shp = shape[i]
GraphicsWindow.PenWidth = shp["pw"] * s
If shp["pw"] > 0 Then
GraphicsWindow.PenColor = shp["pc"]
EndIf
If Text.IsSubText("rect|ell|tri|text|btn", shp["func"]) Then
GraphicsWindow.BrushColor = shp["bc"]
EndIf
If Text.IsSubText("text|btn", shp["func"]) Then
If silverlight Then
fs = Math.Floor(shp["fs"] * 0.9)
Else
fs = shp["fs"]
EndIf
GraphicsWindow.FontSize = fs * s
GraphicsWindow.FontName = shp["fn"]
If shp["fb"] = "False" Then
GraphicsWindow.FontBold = "False"
Else
GraphicsWindow.FontBold = "True"
EndIf
EndIf
If shp["func"] = "rect" Then
shp["obj"] = Shapes.AddRectangle(shp["width"] * s, shp["height"] * s)
ElseIf shp["func"] = "ell" Then
shp["obj"] = Shapes.AddEllipse(shp["width"] * s, shp["height"] * s)
ElseIf shp["func"] = "tri" Then
shp["obj"] = Shapes.AddTriangle(shp["x1"] * s, shp["y1"] * s, shp["x2"] * s, shp["y2"] * s, shp["x3"] * s, shp["y3"] * s)
ElseIf shp["func"] = "line" Then
shp["obj"] = Shapes.AddLine(shp["x1"] * s, shp["y1"] * s, shp["x2"] * s, shp["y2"] * s)
ElseIf shp["func"] = "text" Then
shp["obj"] = Shapes.AddText(shp["text"])
EndIf
x = shp["x"]
y = shp["y"]
shp["rx"] = x
shp["ry"] = y
If silverlight And Text.IsSubText("tri|line", shp["func"]) Then
alpha = Math.GetRadians(shp["angle"])
SB_RotateWorkaround()
shp["wx"] = x
shp["wy"] = y
EndIf
If shp["func"] = "btn" Then
shp["obj"] = Controls.AddButton(shp["caption"], shX + x * s, shY + y * s)
Else
Shapes.Move(shp["obj"], shX + x * s, shY + y * s)
EndIf
If Text.IsSubText("rect|ell|tri|text", shp["func"]) And (shp["angle"] <> 0) And (shp["angle"] <> "") Then
Shapes.Rotate(shp["obj"], shp["angle"])
EndIf
shape[i] = shp
EndFor
grp["shape"] = shape
group[nGroup] = grp
y = Stack.PopValue("local")
x = Stack.PopValue("local")
i = Stack.PopValue("local")
EndSub
Sub Group_Move
' Group | Move a group
' param group[i] - group to move
' param x, y - position to move
' return group[i] - updated group
grp = group[i]
s = grp["scale"]
grp["x"] = x
grp["y"] = y
shape = grp["shape"]
n = Array.GetItemCount(shape)
For j = 1 To n
shp = shape[j]
If silverlight And Text.IsSubText("tri|line", shp["func"]) Then
_x = shp["wx"]
_y = shp["wy"]
Else
_x = shp["rx"]
_y = shp["ry"]
EndIf
Shapes.Move(shp["obj"], grp["x"] + _x * s, grp["y"] + _y * s)
EndFor
group[i] = grp
EndSub
Sub SB_RotateWorkaround
' Small Basic | Rotate workaround for Silverlight
' param shp - current shape
' param x, y - original coordinate
' param alpha - angle [radian]
' returns x, y - workaround coordinate
If shp["func"] = "tri" Then
x1 = -Math.Floor(shp["x3"] / 2)
y1 = -Math.Floor(shp["y3"] / 2)
ElseIf shp["func"] = "line" Then
x1 = -Math.Floor(Math.Abs(shp["x1"] - shp["x2"]) / 2)
y1 = -Math.Floor(Math.Abs(shp["y1"] - shp["y2"]) / 2)
EndIf
ox = x - x1
oy = y - y1
x = x1 * Math.Cos(alpha) - y1 * Math.Sin(alpha) + ox
y = x1 * Math.Sin(alpha) + y1 * Math.Cos(alpha) + oy
EndSub
Sub SB_Workaround
' Small Basic | Workaround for Silverlight
' returns silverlight - "True" if in remote
color = GraphicsWindow.GetPixel(0, 0)
If Text.GetLength(color) > 7 Then
silverlight = "True"
msWait = 300
Else
silverlight = "False"
EndIf
EndSub
Sub Shapes_CalcWidthAndHeight
' Shapes | Calculate total width and height of shapes
' param shape[] - shape array
' return shWidth, shHeight - total size of shapes
For i = i To Array.GetItemCount(shape)
shp = shape[i]
If shp["func"] = "tri" Or shp["func"] = "line" Then
xmin = shp["x1"]
xmax = shp["x1"]
ymin = shp["y1"]
ymax = shp["y1"]
If shp["x2"] < xmin Then
xmin = shp["x2"]
EndIf
If xmax < shp["x2"] Then
xmax = shp["x2"]
EndIf
If shp["y2"] < ymin Then
ymin = shp["y2"]
EndIf
If ymax < shp["y2"] Then
ymax = shp["y2"]
EndIf
If shp["func"] = "tri" Then
If shp["x3"] < xmin Then
xmin = shp["x3"]
EndIf
If xmax < shp["x3"] Then
xmax = shp["x3"]
EndIf
If shp["y3"] < ymin Then
ymin = shp["y3"]
EndIf
If ymax < shp["y3"] Then
ymax = shp["y3"]
EndIf
EndIf
shp["width"] = xmax - xmin
shp["height"] = ymax - ymin
EndIf
If i = 1 Then
shWidth = shp["x"] + shp["width"]
shHeight = shp["y"] + shp["height"]
Else
If shWidth < shp["x"] + shp["width"] Then
shWidth = shp["x"] + shp["width"]
EndIf
If shHeight < shp["y"] + shp["height"] Then
shHeight = shp["y"] + shp["height"]
EndIf
EndIf
shape[i] = shp
EndFor
EndSub