GraphicsWindow.Title = "Draw Moon - Sequence Quiz"
Init()
Form()
nQuiz = Array.GetItemCount(quiz)
For q = 1 To nQuiz
Shapes.HideShape(o)
Shapes.HideShape(x1)
Shapes.HideShape(x2)
seq = quiz[q]
x = xQuiz
y = yQuiz
DrawBackground()
DrawPattern()
buttonClicked = "False"
While Not[buttonClicked]
Program.Delay(200)
EndWhile
seq = Controls.GetTextBoxText(tbox)
x = xAns
y = yAns
DrawBackground()
DrawPattern()
Check()
Program.Delay(2000)
x = xAns
y = yAns
DrawBackground()
EndFor
Shapes.HideShape(o)
Shapes.HideShape(x1)
Shapes.HideShape(x2)
x = xQuiz
y = yQuiz
DrawBackground()
For scale = 1 To 4 Step 0.5
Shapes.Zoom(total, scale, scale)
Program.Delay(500)
EndFor
Sub Check
' return count - count up if match
match = "True"
nCheck = Array.GetItemCount(point)
For i = 1 To nCheck
x = xQuiz + point[i]["x"] * large
y = yQuiz + point[i]["y"] * large
cQuiz = GraphicsWindow.GetPixel(x, y)
x = xAns + point[i]["x"] * large
y = yAns + point[i]["y"] * large
cAns = GraphicsWindow.GetPixel(x, y)
If cQuiz <> cAns Then
match = "False"
i = nCheck ' exit For
EndIf
EndFor
If match Then
count = count + 1
Shapes.ShowShape(o)
Else
Shapes.ShowShape(x1)
Shapes.ShowShape(x2)
EndIf
If count = 0 Then
Shapes.SetText(total, "0 point")
Else
Shapes.SetText(total, Math.Floor(count /nQuiz * 100) + " points")
EndIf
EndSub
Sub DrawBackground
' param x, y - positon of the background
' param size - size of the background
_y = y
For j = 1 To 8
_x = x
For k = 1 To 8
If Math.Remainder(j + k, 2) = 0 Then
GraphicsWindow.BrushColor = "Gray"
Else
GraphicsWindow.BrushColor = "DimGray"
EndIf
GraphicsWindow.FillRectangle(_x, _y, size / 8, size / 8)
_x = _x + size / 8
EndFor
_y = _y + size / 8
EndFor
GraphicsWindow.DrawRectangle(x, y, size, size)
Program.Delay(500)
EndSub
Sub DrawPattern
' param seq - sequence of patterns
' param x, y - position of the pattern
' param size - size of the pattern
nSeq = Text.GetLength(seq)
For p = 1 To nSeq
id = Text.GetSubText(seq, p, 1)
If Array.ContainsIndex(pattern, id) Then
ptn = pattern[id]
_x = x + ptn["x"] * size
_y = y + ptn["y"] * size
_width = ptn["width"] * size
_height = ptn["height"] * size
GraphicsWindow.BrushColor = ptn["color"]
If ptn["type"] = "rect" Then
GraphicsWindow.FillRectangle(_x, _y, _width, _height)
ElseIf ptn["type"] = "ell" Then
GraphicsWindow.FillEllipse(_x, _y, _width, _height)
EndIf
Else
Program.Delay(1000)
EndIf
EndFor
EndSub
Sub Form
gw = 598
gh = 428
fs = 20
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
GraphicsWindow.FontName = "Courier New"
GraphicsWindow.FontSize = fs
GraphicsWindow.BackgroundColor = "Blue"
GraphicsWindow.BrushColor = "Black"
small = 80
large = 160
gapX = 10
gapY = 30
y = gapY
n = Array.GetItemCount(pattern)
index = Array.GetAllIndices(pattern)
x = (gw - n * small - (n - 1) * gapX) / 2
xQuiz = x
yQuiz = y + small + gapY + fs
xAns = gw - large - x
yAns = yQuiz
tbox = Controls.AddTextBox(x , yQuiz + large + gapY + 0.1 * fs)
bw = 2.9 * fs
Controls.SetSize(tbox, gw - 2 * x - bw - gapX, 1.5 * fs)
Controls.AddButton("Draw", gw - x - bw, yQuiz + large + gapY)
dx = (small - fs * 0.6) / 2
size = small
For i = 1 To n
DrawBackground()
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.DrawText(x + dx, y + small, index[i])
seq = index[i]
DrawPattern()
x = x + (small + gapX)
EndFor
x = xQuiz
y = yQuiz
size = large
DrawBackground()
x = xAns
y = yAns
DrawBackground()
size = large * 0.8
x = (gw - size) / 2
y = yQuiz + (large - size)
GraphicsWindow.BrushColor = "White"
total = Shapes.AddText("")
Shapes.Move(total, x, yQuiz)
GraphicsWindow.PenWidth = 12
GraphicsWindow.PenColor = "Lime"
GraphicsWindow.BrushColor = "Blue"
o = Shapes.AddEllipse(size, size)
Shapes.Move(o, x, y)
Shapes.HideShape(o)
GraphicsWindow.PenColor = "Red"
x1 = Shapes.AddLine(0, 0, size, size)
Shapes.Move(x1, x, y)
Shapes.HideShape(x1)
x2 = Shapes.AddLine(0, size, size, 0)
Shapes.Move(x2, x, y)
Shapes.HideShape(x2)
GraphicsWindow.PenWidth = 2
GraphicsWindow.PenColor = "Black"
size = large
Controls.ButtonClicked = OnButtonClicked
EndSub