// Classical effect made with CoolBasic @ Assembly 2009
 
SCREEN 800, 600
 
Dim ord(6, 3)
 
ord(1, 1) = 1 : ord(1, 2) = 2 : ord(1, 3) = 3
ord(2, 1) = 1 : ord(2, 2) = 3 : ord(2, 3) = 2
ord(3, 1) = 2 : ord(3, 2) = 1 : ord(3, 3) = 3
ord(4, 1) = 2 : ord(4, 2) = 3 : ord(4, 3) = 1
ord(5, 1) = 3 : ord(5, 2) = 1 : ord(5, 3) = 2
ord(6, 1) = 3 : ord(6, 2) = 2 : ord(6, 3) = 1
 
img = MakeImage(100, 600)
DrawToImage img
	For y = 0 To 61
		For x = 0 To 18
			a = Abs(5 - x) * 50
			If (x + y) Mod 2 Then
				Color 255 - a, 0, 255 - a
			Else
				Color 0, 0, 0
			EndIf
			Box (x - 1) * 10, y * 10, 10, 10
		Next x
	Next y
DrawToScreen
 
MaskImage img, 100, 100, 100
 
Repeat
	angle = WrapAngle(angle + 2)
	ca# = Cos(angle) * 10
	cs# = Sin(angle) * 10
 
	Color 127 + sa * 125, 127 - sa * 125, 0
	For x = 0 To 18
		For y = 0 To 16
			If (x + y) Mod 2 Then Box (x - 1) * 50 + ca, (y - 1) * 50 - cs, 50, 50
		Next y
	Next x
 
	For y = 0 To 150
		y2 = angle + y
		yy = y Shl 2
 
		z1# = Sin(y2)
		z2# = Sin(y2 + 120)
		z3# = Sin(y2 + 240)
 
		If (z1 > z2 And z2 > z3) Then
			order = 1
		ElseIf (z1 > z3 And z3 > z2) Then
			order = 2
		ElseIf (z2 > z1 And z1 > z3) Then
			order = 3
		ElseIf (z2 > z3 And z3 > z1) Then
			order = 4
		ElseIf (z3 > z1 And z1 > z2) Then
			order = 5
		Else
			order = 6
		EndIf
 
		DrawImageBox img, 355 + Sin(y2 + ord(order, 1) * 120) * 100, yy, 0, yy, 90, 4
		DrawImageBox img, 355 + Sin(y2 + ord(order, 2) * 120) * 100, yy, 0, yy, 90, 4
		DrawImageBox img, 355 + Sin(y2 + ord(order, 3) * 120) * 100, yy, 0, yy, 90, 4
	Next y
	Text 0, 0, FPS()
 
	SetWindow Str(FPS())
	DrawScreen
Forever