Microsoft Small Basic

Program Listing: CJR855
'Optical illusions all-in-one; requires FC extension; by Vitexikora
GraphicsWindow.Hide()
illtext[1] = "Focus on any of the white balls. You will see the others black. /*by litdev*\"
illtext[2] = "Is the umbrella rotating? No!, focus on one line. Still rotating? Add a finger by the screen, you will see it static. /*by litdev*\"
illtext[3] = "Is it really a square ? /*by litdev*\"
illtext[4] = "If you look at the centre cross, it appears that a green 'ghost' dot appears in the space. /*by litdev*\"
illtext[5] = "The 'blue' and 'green' are both the same colour (Cyan). I know it is hard to belive, but check it yourself. /*by litdev*\"
illtext[6] = "Are the lines collinear ? /*by litdev*\"
illtext[7] = "The thick line in the center seems to be light to dark, but it is of one color /*by Vitexikora*\"
igw=500
igh=500
GraphicsWindow.Title="Optical Illusions"
Controls.LoadTheme("XPRoyale")
DrawGW()
GraphicsWindow.KeyDown=OnKeyDown
GraphicsWindow.Show()



Sub illusion1
ClearMenuGW()
gw=500
gh=gw
GraphicsWindow.BackgroundColor = "Gray"
GraphicsWindow.BrushColor = "Black"
For i = 1 To 8
For j = 1 To 8
GraphicsWindow.FillRectangle((i-1)*gw/8+5,(j-1)*gw/8+5,gw/8-10,gw/8-10)
EndFor
EndFor
GraphicsWindow.BrushColor = "White"
For i = 1 To 7
For j = 1 To 7
GraphicsWindow.FillEllipse(i*gw/8-7,j*gw/8-7,14,14)
EndFor
EndFor
EndSub


Sub illusion2
ClearMenuGW()
status="go!"
gw = 600
gh = 600
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
GraphicsWindow.BackgroundColor = GraphicsWindow.GetColorFromRGB(200,175,175)

segments = 16
rad = gw/4
cx = gw/2
cy = gh/2

offset = 0
theta1 = 0
x1 = cx+rad*Math.Cos(theta1)
y1 = cy+rad*Math.Sin(theta1)
While (status="go!")
offset = offset+1
For i = 1 To segments
theta2 = theta1+2*Math.Pi/segments
x2 = cx+rad*Math.Cos(theta2)
y2 = cy+rad*Math.Sin(theta2)
j = Math.Remainder(i+offset,segments)
R = 50+Math.Abs((j/(segments-1)-0.5)*300)
G = R/2
B = R/2
GraphicsWindow.BrushColor = GraphicsWindow.GetColorFromRGB(R,G,B)
GraphicsWindow.FillTriangle(cx,cy,x1,y1,x2,y2)
GraphicsWindow.PenColor = GraphicsWindow.GetColorFromRGB(100,75,75)
GraphicsWindow.DrawLine(cx,cy,x1,y1)
GraphicsWindow.DrawLine(cx,cy,x2,y2)
theta1 = theta2
x1 = x2
y1 = y2
EndFor
Program.Delay(30)
EndWhile
EndSub


Sub illusion3
ClearMenuGW()
GraphicsWindow.PenWidth = 0
GraphicsWindow.BackgroundColor = "Gray"
For i = 20 To 1 Step -1
rad = i*10
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.FillEllipse(500/2-rad,500/2-rad,2*rad,2*rad)
rad = rad-5
GraphicsWindow.BrushColor = "White"
GraphicsWindow.FillEllipse(500/2-rad,500/2-rad,2*rad,2*rad)
EndFor
GraphicsWindow.PenWidth = 4
GraphicsWindow.PenColor = "Red"
GraphicsWindow.DrawRectangle(100,100,300,300)
EndSub


Sub illusion4
ClearMenuGW()
status="go!"
gw = 500
gh = gw
GraphicsWindow.BackgroundColor = "LightGray"
GraphicsWindow.PenWidth = 0

GraphicsWindow.BrushColor = "Black"
GraphicsWindow.FillRectangle(gw/2-2,gh/2-10,4,20)
GraphicsWindow.FillRectangle(gw/2-10,gh/2-2,20,4)

GraphicsWindow.BrushColor = "Magenta"
For i = 1 To 12
ball[i] = Shapes.AddEllipse(40,40)
theta = i*2*Math.Pi/12
x = gw/2+200*Math.Cos(theta)
y = gh/2+200*Math.Sin(theta)
Shapes.Move(ball[i],x-20,y-20)
EndFor

While(status="go!")
For i = 1 To 12
Shapes.HideShape(ball[i])
Program.Delay(150)
Shapes.ShowShape(ball[i])
EndFor
EndWhile
EndSub


Sub illusion5
ClearMenuGW()
gw = 500
gh = gw
GraphicsWindow.PenWidth = 0

For row = 1 To 10
y = (row-1)*50
For col = 1 To 50
x = (col-1)*10
rem = Math.Remainder(row,4)
If (rem = 0) Then
GraphicsWindow.BrushColor = "Magenta"
GraphicsWindow.FillRectangle(x,y,5,gh/10)
GraphicsWindow.BrushColor = "Orange"
GraphicsWindow.FillRectangle(x+5,y,5,gh/10)
ElseIf (rem = 1) Then
GraphicsWindow.BrushColor = "Magenta"
GraphicsWindow.FillRectangle(x,y,5,gh/10)
GraphicsWindow.BrushColor = "Cyan"
GraphicsWindow.FillRectangle(x+5,y,5,gh/10)
ElseIf (rem = 2) Then
GraphicsWindow.BrushColor = "Magenta"
GraphicsWindow.FillRectangle(x,y,5,gh/10)
GraphicsWindow.BrushColor = "Orange"
GraphicsWindow.FillRectangle(x+5,y,5,gh/10)
Else
GraphicsWindow.BrushColor = "Cyan"
GraphicsWindow.FillRectangle(x,y,5,gh/10)
GraphicsWindow.BrushColor = "Orange"
GraphicsWindow.FillRectangle(x+5,y,5,gh/10)
EndIf
EndFor
EndFor
EndSub


Sub illusion6
ClearMenuGW()
GraphicsWindow.BackgroundColor = "Gray"
For row = 1 To 20
For col = 0 To 10
x = (col-1)*50+2
y = (row-1)*25+2
If (Math.Remainder(row,2) = 1) Then
x = x+12
EndIf
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.FillRectangle(x,y,23,23)
GraphicsWindow.BrushColor = "White"
GraphicsWindow.FillRectangle(x+25,y,23,23)
EndFor
EndFor
EndSub


Sub illusion7
ClearMenuGW()
GraphicsWindow.PenWidth = 2
GraphicsWindow.BackgroundColor = "Gray"
For i=0 To 450
GraphicsWindow.PenColor = GraphicsWindow.GetColorFromRGB(0+(i/(450/255)),0+(i/(450/255)),0+(i/(450/255)))
GraphicsWindow.DrawLine(25+i,25,25+i,475)
EndFor
GraphicsWindow.BrushColor="Gray"
GraphicsWindow.FillRectangle(40,230,420,40)
EndSub


Sub ClearMenuGW
For w=1 To 7
Controls.Remove(butt[w])
EndFor
GraphicsWindow.Clear()
EndSub


Sub OnKeyDown
If GraphicsWindow.LastKey="Escape" Then
prevstat=status
status="stop!"

If prevstat="go!" Then
Program.Delay(300)
GraphicsWindow.DrawText(200,200,"Stopping...")
Program.Delay(700)
GraphicsWindow.Clear()
EndIf

GraphicsWindow.Clear()
DrawGW()
EndIf
EndSub


Sub DrawGW
GraphicsWindow.Width=igw
GraphicsWindow.Height=igh
GraphicsWindow.BackgroundColor="Ivory"
GraphicsWindow.BrushColor = "DeepSkyBlue"
GraphicsWindow.FontSize=10
For q=1 To 7
butt[q] = Controls.AddButton(100,22,"("+q+")")
Controls.Move(butt[q],30,25+(q*50))
Controls.RegisterMouseUpEvent(butt[q],"illusion"+q)
GraphicsWindow.DrawBoundText(140,23+(q*50),350,illtext[q])
EndFor
GraphicsWindow.FontSize=20
GraphicsWindow.DrawText(170,10,"Optical Illusions")
GraphicsWindow.FontSize=15
GraphicsWindow.BrushColor="Orange"
GraphicsWindow.DrawText(30,440," !!--- Press [Esc] to return to this menu ---!! ")
EndSub