Microsoft Small Basic

Program Listing: ZBB577
' Optical Illusion 2
' Programmed by Nonki Takahashi.
' Last update 2016-07-26
GraphicsWindow.Title = "Optical Illusion 2"
gw = 598
gh = 428
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
GraphicsWindow.PenWidth = 0
color[1] = "c0=Blue;c1=Yellow;c=Lime;"
color[2] = "c0=Magenta;c1=Orange;c=Cyan;"
color[3] = "c0=Black;c1=White;c=Gray;"
nColor = Array.GetItemCount(color)
iColor = 1
While "True"
GraphicsWindow.Clear()
c0 = color[iColor]["c0"]
c1 = color[iColor]["c1"]
GraphicsWindow.BrushColor = c0
r0 = Shapes.AddRectangle(gw / 2, gh)
Shapes.Move(r0, 0, 0)
GraphicsWindow.BrushColor = c1
r1 = Shapes.AddRectangle(gw / 2, gh)
Shapes.Move(r1, gw / 2, 0)
c = color[iColor]["c"]
x = 50
y = 30
width = (gw - 150) / 2
height = Math.Floor((gh - 60) / 10) * 10
DrawRectangle()
x = gw / 2 + 25
DrawRectangle()
gap = 10
DrawStripe()
MoveStripe()
iColor = iColor + 1
If nColor < iColor Then
iColor = 1
EndIf
EndWhile
Sub DrawStripe
i = 1
For y = 0 To gh Step gap
If Math.Remainder(i, 2) = 1 Then
GraphicsWindow.BrushColor = c0
stripe[i] = Shapes.AddRectangle(gw / 2, gap)
Shapes.Move(stripe[i], gw / 2, y)
Else
GraphicsWindow.BrushColor = c1
stripe[i] = Shapes.AddRectangle(gw / 2, gap)
Shapes.Move(stripe[i], 0, y)
EndIf
'Shapes.SetOpacity(stripe[i], 50)
i = i + 1
EndFor
EndSub
Sub DrawRectangle
GraphicsWindow.BrushColor = c
rect = Shapes.AddRectangle(width, height)
Shapes.Move(rect, x, y)
EndSub
Sub MoveStripe
n = Array.GetItemCount(stripe)
Program.Delay(3000)
For j = 1 To gw / 2
Shapes.Move(r0, Shapes.GetLeft(r0) - 1, 0)
Shapes.Move(r1, Shapes.GetLeft(r1) + 1, 0)
For i = 1 To n
x = Shapes.GetLeft(stripe[i])
If gw / 2 <= x Then
x = x + 1
Else
x = x - 1
EndIf
y = Shapes.GetTop(stripe[i])
Shapes.Move(stripe[i], x, y)
EndFor
Program.Delay(10)
EndFor
Program.Delay(1000)
For j = 1 To gw / 2
Shapes.Move(r0, Shapes.GetLeft(r0) + 1, 0)
Shapes.Move(r1, Shapes.GetLeft(r1) - 1, 0)
For i = 1 To n
x = Shapes.GetLeft(stripe[i])
If gw / 2 <= x Then
x = x - 1
Else
x = x + 1
EndIf
y = Shapes.GetTop(stripe[i])
Shapes.Move(stripe[i], x, y)
EndFor
Program.Delay(10)
EndFor
Program.Delay(3000)
EndSub