Sub OnTick
t = t + 1
If Math.Remainder(t, 8) = 1 Then
For i = 1 To 2
Shapes.HideShape(eyelids[i])
EndFor
ElseIf Math.Remainder(t, 8) = 0 Then
For i = 1 To 2
Shapes.ShowShape(eyelids[i])
EndFor
EndIf
EndSub
Sub OnMouseMove
mx = GraphicsWindow.MouseX
my = GraphicsWindow.MouseY
If Not[moving] Then
moving = "True"
For i = 2 To 4
x = mx - ox[1]
y = my - oy[1]
Math_CartesianToPolar()
d = Math.SquareRoot(x * x + y * y)
If (d < sz[1] / 2) And (d < (sz[1] - sz[i])) Then
r = d / 2
Else
r = (sz[1] - sz[i]) / 2
EndIf
_a = Math.GetRadians(a)
ox[i] = ox[1] + r * Math.Cos(_a)
oy[i] = oy[1] + r * Math.Sin(_a)
Shapes.Move(ell[i], ox[i] - sz[i] / 2, oy[i] - sz[i] / 2)
x = mx - ox[5]
y = my - oy[5]
Math_CartesianToPolar()
d = Math.SquareRoot(x * x + y * y)
If (d < sz[5] / 2) And (d < (sz[5] - sz[i + 4])) Then
r = d / 2
Else
r = (sz[5] - sz[i + 4]) / 2
EndIf
_a = Math.GetRadians(a)
ox[i + 4] = ox[5] + r * Math.Cos(_a)
oy[i + 4] = oy[5] + r * Math.Sin(_a)
Shapes.Move(ell[i + 4], ox[i + 4] - sz[i + 4] / 2, oy[i + 4] - sz[i + 4] / 2)
EndFor
For i = 1 To 2
j = 4 + (i - 1) * 4
Shapes.Move(rectangle[i], ox[j] - 30 / 2, oy[j] - 10 / 2)
Shapes.Move(eyelids[i], ox[j] - sz[j] / 2, oy[j] - sz[j] / 2)
EndFor
moving = "False"
EndIf
EndSub
Sub Math_CartesianToPolar
' Math | convert Cartesian coodinate to polar coordinate
' param x, y - Cartesian coordinate
' return r, a - polar Coordinate (0<=a<360)
r = Math.SquareRoot(x * x + y * y)
If x = 0 And y > 0 Then
a = 90 ' [degree]
ElseIf x = 0 And y < 0 Then
a = -90
ElseIf x = 0 And y = 0 Then
a = 0
Else
a = Math.ArcTan(y / x) * 180 / Math.Pi
EndIf
' at this point -90<=a<=90
If x < 0 Then
a = a + 180
ElseIf x >= 0 And y < 0 Then
a = a + 360
EndIf
' at this point 0<=a<360
EndSub