Here is a simple colour-cycle effect which produces nice visual eye candy. Especially on the Galaxy's Super-Amoled screen
B4X:
' Colour blaze - Jim Brown - v1.0
' NOTE: Uses the "Phone" library
Sub Process_Globals
Dim col As List
Dim rDir,gDir,bDir As Int
Dim time As Timer
Dim awake As PhoneWakeState
End Sub
Sub Globals
' display-related variables
Dim can As Canvas
Dim rec As Rect
Dim cx,cy As Int
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime=True Then
' set inital colours
col.Initialize
For n=1 To 28
col.Add(Colors.RGB(n*2,0,n*4))
Next
rDir=Rnd(1,4) : gDir=Rnd(1,4) : bDir=Rnd(1,4)
End If
can.Initialize(Activity)
cx=Activity.Width : cy=Activity.Height
time.Initialize("Timer1",30)
End Sub
Sub Activity_Resume
time.Enabled=True
awake.KeepAlive(True)
End Sub
Sub Activity_Pause (UserClosed As Boolean)
time.Enabled=False
awake.ReleaseKeepAlive
End Sub
Sub Timer1_Tick
' update colors
col.RemoveAt(0)
Dim newcol As Int
newcol=col.Get(col.Size-1)
newcol=AdjustColor(newcol)
col.Add(newcol)
' render rects
Dim sx,sy,aspX,aspY As Float
aspX=(cx/2)/col.Size : aspY=(cy/2)/col.Size
sx=0 : sy=0
For i=0 To col.Size-1
rec.Initialize(sx,sy,cx-sx,cy-sy)
can.DrawRect(rec,col.Get(i),True,0)
sx=sx+aspX : sy=sy+aspY
Next
Activity.Invalidate
End Sub
Sub AdjustColor(Color As Int) As Int
Dim r,g,b As Int
' a = Bit.UnsignedShiftRight(Bit.And(Color, 0xff000000), 24)
r = Bit.UnsignedShiftRight(Bit.And(Color, 0xff0000), 16)
g = Bit.UnsignedShiftRight(Bit.And(Color, 0xff00), 8)
b = Bit.And(Color, 0xff)
r=r+rDir : g=g+gDir : b=b+bDir
If r<0 Then
r=0 : rDir=Rnd(8,30)
End If
If g<0 Then
g=0 : gDir=Rnd(8,30)
End If
If b<0 Then
b=0 : bDir=Rnd(8,30)
End If
If r>255 Then
r=255 : rDir=-Rnd(8,30)
End If
If g>255 Then
g=255 : gDir=-Rnd(8,30)
End If
If b>255 Then
b=255 : bDir=-Rnd(8,30)
End If
Return Colors.RGB(r,g,b)
End Sub