Microsoft Small Basic

Program Listing: TQH071
' Optical Illusion #01 ()
' Program by Nonki Takahashi 2014
'
GraphicsWindow.Title = "Optical Illusion #01"
Not = "False=True;True=False;"
gw = 598
gh = 428
gap = 40
gc = "LightGray"
debug = "False"
GraphicsWindow.BackgroundColor = "DimGray"
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
If debug Then
DrawGrid()
EndIf
url = "http://www.nonkit.com/smallbasic.files/"
t1 = Shapes.AddImage(url + "Turtle.png")
Shapes.Zoom(t1, 0.48, 0.48)
'Shapes.SetOpacity(t1, 50)
tx1 = 60
tx2 = 290
Shapes.Move(t1, tx1, 96)
t2 = Shapes.AddImage(url + "Turtle.png")
Shapes.Zoom(t2, 0.48, 0.48)
'Shapes.SetOpacity(t2, 50)
Shapes.Move(t2, tx2, 96)
column = "True"
y0 = 5.5 * gap
x1 = gap
y1 = 2 * gap
x2 = 4 * gap
y2 = gap
Draw3DGrid()
column = "False"
x1 = 4 * gap
y1 = gap
x2 = 10 * gap
y2 = 4 * gap
Draw3DGrid()
x1 = 10 * gap
y1 = 4 * gap
x2 = 14 * gap
y2 = 3.5 * gap
Draw3DGrid()
duration = 2000
While "True"
Program.Delay(5 * duration)
Shapes.Animate(t2, tx1, 96, duration)
Program.Delay(duration)
Shapes.Animate(t2, tx2, 96, duration)
Program.Delay(duration)
EndWhile
Sub DrawGrid
GraphicsWindow.PenColor = "Gray"
For y = 0 To gh Step gap
GraphicsWindow.DrawLine(0, y, gw, y)
EndFor
For x = 0 To gw Step gap
GraphicsWindow.DrawLine(x, 0, x, gh)
EndFor
EndSub
Sub Draw3DGrid
' param y0, x1, y1, x2, y2
' param column - flag
GraphicsWindow.PenColor = gc
GraphicsWindow.DrawLine(x1, y1, x1, 2 * y0 - y1)
GraphicsWindow.DrawLine(x2, y2, x2, 2 * y0 - y2)
CalcMidX()
If Not[column] Then
GraphicsWindow.DrawLine(x3, y3, x3, 2 * y0 - y3)
Stack.PushValue("stack", h1)
Stack.PushValue("stack", h2)
Stack.PushValue("stack", x2)
Stack.PushValue("stack", y2)
Stack.PushValue("stack", x3)
Stack.PushValue("stack", y3)
x2 = x3
y2 = y3
CalcMidX()
GraphicsWindow.DrawLine(x3, y3, x3, 2 * y0 - y3)
y3 = Stack.PopValue("stack")
x3 = Stack.PopValue("stack")
y2 = Stack.PopValue("stack")
x2 = Stack.PopValue("stack")
Stack.PushValue("stack", x1)
Stack.PushValue("stack", y1)
Stack.PushValue("stack", x3)
Stack.PushValue("stack", y3)
x1 = x3
y1 = y3
CalcMidX()
GraphicsWindow.DrawLine(x3, y3, x3, 2 * y0 - y3)
y3 = Stack.PopValue("stack")
x3 = Stack.PopValue("stack")
y1 = Stack.PopValue("stack")
x1 = Stack.PopValue("stack")
h2 = Stack.PopValue("stack")
h1 = Stack.PopValue("stack")
EndIf
For i = 0 To 3
_y1 = y1 + i * h1 * 2 / 3
_y2 = y2 + i * h2 * 2 / 3
GraphicsWindow.DrawLine(x1, _y1, x2, _y2)
EndFor
EndSub
Sub CalcMidX
' param y0, x1, y1, x2, y2
' return x3, y3
h1 = y0 - y1
h2 = y0 - y2
x3 = x1 + (x2 - x1) * h1 / (h1 + h2)
y3 = y1 + (y2 - y1) * (x3 - x1) / (x2 - x1)
EndSub