I've made some amendments. Pass your game 'Frames per second' and the number of seconds you want it to take to complete a full day night cycle in the DAYNIGHTinit function. Should be stable for an hour or so max. You probably don't want to be updating the colours every frame as your unlikely to see a difference.
Graphics3D 1024,768
SetBuffer BackBuffer()
Global camera = CreateCamera()
Global plane = CreatePlane()
RotateEntity plane, -90,0,0
PositionEntity plane, 0,0,5
Global DNcurrent, DNmod, DNdiv
DAYNIGHTinit( 50 , 120 )
While Not KeyDown(1)
DAYNIGHTupdate()
RenderWorld()
Text 0,0, "Current: " + DNcurrent
Text 0,10,"Mod : " + DNmod
Text 0,20,"Div : " + DNdiv
Flip
Wend
End
;====================================================================
;====================================================================
;====================================================================
Function DAYNIGHTinit( FPS , Time )
Speed# = 4.0 / ( FPS * Time )
DNmod = 4 / Speed
DNdiv = 1 / Speed
End Function
;====================================================================
;====================================================================
;====================================================================
Function DAYNIGHTupdate()
DNcurrent = ( DNcurrent + 1 ) Mod DNmod
COLORinterpolate( DNcurrent / Float( DNdiv ) , 64,255,64, 64,64,255, 255,64,64, 255,64,255 )
End Function
;====================================================================
;====================================================================
;====================================================================
Function COLORinterpolate( t#, r1,g1,b1 , r2, g2, b2 , r3, g3, b3 , r4, g4, b4 )
;get nearest integer below
i = Floor( t )
;get timestep 0 .. 1
t = t - i
Select i
Case 0
r = r1 + ( r2 - r1 ) * t
g = g1 + ( g2 - g1 ) * t
b = b1 + ( b2 - b1 ) * t
Case 1
r = r2 + ( r3 - r2 ) * t
g = g2 + ( g3 - g2 ) * t
b = b2 + ( b3 - b2 ) * t
Case 2
r = r3 + ( r4 - r3 ) * t
g = g3 + ( g4 - g3 ) * t
b = b3 + ( b4 - b3 ) * t
Case 3
r = r4 + ( r1 - r4 ) * t
g = g4 + ( g1 - g4 ) * t
b = b4 + ( b1 - b4 ) * t
End Select
AmbientLight r, g, b
End Function