Sub CalcAngles
For i = 1 To 2
x = mx - eyeX[i]
y = my - eyeY[i]
Math_CartesianToPolar()
eyeAngle[i] = a
EndFor
EndSub
Sub DrawCurly
r = 5
dr = 5 / (360 / 10)
a0 = Math.GetRandomNumber(360)
For a = 0 To 360 Step 10
_a = Math.GetRadians(a + a0)
cx = cx + r * a / 360 * Math.Cos(_a)
cy = cy + r * a / 360 * Math.Sin(_a)
_x = cx - r / 2
_y = cy - r / 2
l = (360 - a) / 3
GetColors()
GraphicsWindow.BrushColor = root
GraphicsWindow.FillEllipse(_x, _y, 2*r, 2*r)
GraphicsWindow.BrushColor = tip
GraphicsWindow.FillEllipse(_x + 1, _y + 1, 2*r, 2*r)
r = r - dr
EndFor
EndSub
Sub FillCurlyEllipse
' param["x"], param["y"] - left top corner
' param["width"], param["height"] - size
GetParam()
If color = "Black" Then
GraphicsWindow.BrushColor = "#111111"
ElseIf color = "White" Then
GraphicsWindow.BrushColor = "#DDDDDD"
ElseIf color = "Mocha" Then
GraphicsWindow.BrushColor = "#663300"
EndIf
GraphicsWindow.FillEllipse(x, y, width, height)
If debug Then
Goto fce_exit
EndIf
For i = 1 To (width * height) / (5 * 5)
rx = Math.GetRandomNumber(width / 2)
ry = Math.GetRandomNumber(height / 2)
a = Math.GetRandomNumber(360)
_a = Math.GetRadians(a)
cx = x + width / 2 + rx * Math.Cos(_a)
cy = y + height / 2 + ry * Math.Sin(_a)
DrawCurly()
EndFor
fce_exit:
EndSub
Sub FillCurlyRectangle
' param["x"], param["y"] - left top corner
' param["width"], param["height"] - size
GetParam()
If color = "Black" Then
GraphicsWindow.BrushColor = "#111111"
ElseIf color = "White" Then
GraphicsWindow.BrushColor = "#DDDDDD"
ElseIf color = "Mocha" Then
GraphicsWindow.BrushColor = "#663300"
EndIf
GraphicsWindow.FillRectangle(x, y, width, height)
If debug Then
Goto fcr_exit
EndIf
For i = 1 To (width * height) / (5 * 5)
cx = x + Math.GetRandomNumber(width)
cy = y + Math.GetRandomNumber(height)
DrawCurly()
EndFor
fcr_exit:
EndSub
Sub GetColors
α = (120 - l) * 255 / 120
dec = α
Math_Dec2Hex()
If color = "Black" Then
tip = "#" + hex + "000000"
root = "#" + hex + "222222"
ElseIf color = "White" Then
tip = "#" + hex + "FFFFFF"
root = "#" + hex + "DDDDDD"
ElseIf color = "Mocha" Then
tip = "#" + hex + "663300"
root = "#" + hex + "442200"
EndIf
EndSub
Sub GetParam
x = param["x"]
y = param["y"]
width = param["width"]
height = param["height"]
EndSub
Sub MoveEyes
_a = Math.GetRadians(eyeAngle[1])
x = eyeX[1] + rMove * Math.Cos(_a)
y = eyeY[1] + rMove * Math.Sin(_a)
Shapes.Move(eye[1], x - eyeWidth[1] / 2, y - eyeHeight[1] / 2)
_a = Math.GetRadians(eyeAngle[2])
x = eyeX[2] + rMove * Math.Cos(_a)
y = eyeY[2] + rMove * Math.Sin(_a)
Shapes.Move(eye[2], x - eyeWidth[2] / 2, y - eyeHeight[2] / 2)
EndSub
Sub OnButtonClicked
buttonClicked = "True"
EndSub
Sub OnMouseMove
mouseMove = "True"
mx = GraphicsWindow.MouseX
my = GraphicsWindow.MouseY
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
Sub Math_Dec2Hex
' Math | Convert decimal to hexadecimal
' param dec
' param hex
Stack.PushValue("math", dec)
hex = ""
While dec > 0
mod = Math.Remainder(dec, 16)
hex = Text.Append(Text.GetSubText("0123456789ABCDEF", mod + 1, 1), hex)
dec = Math.Floor(dec / 16)
EndWhile
If Text.GetLength(hex) = 0 Then
hex = "00"
ElseIf Text.GetLength(hex) = 1 Then
hex = Text.Append("0", hex)
EndIf
dec = Stack.PopValue("math")
EndSub