Strangeness!!!!
Blitz3D Forums/Blitz3D Programming/Strangeness!!!!
| ||
Why does this not work? Basically it should chnage the background colour smoothly. It does it once but then when the counter is reset to 0 it doesn't work! EH????? Graphics3D 800,600,32,2 SeedRnd MilliSecs camera = CreateCamera() light=CreateLight() old_r%=Rnd(0, 255) old_g%=Rnd(0, 255) old_b%=Rnd(0, 255) r = Rnd(50, 255) g = Rnd(50, 255) b = Rnd(50, 255) CameraClsColor camera, old_r,old_g,old_b Global counter=0 While Not KeyDown( 28 ) counter=counter + 1 If counter > 100 r=Rnd(50, 255) g=Rnd(50, 255) b=Rnd(50, 255) EndIf If r < old_r old_r = old_r - 1 ElseIf r > old_r old_r = old_r + 1 EndIf If g < old_g old_g = old_g - 1 ElseIf g > old_g old_g = old_g + 1 EndIf If b < old_b old_b = old_b - 1 ElseIf b > old_b old_b = old_b + 1 EndIf If r = old_r counter = 0 EndIf CameraClsColor camera, old_r, old_g, old_b UpdateWorld RenderWorld Text 1,1,"counter:" + counter + " old_r:" + old_r + " r:" + r + " old_g:" + old_g + " g:" + g + " old_b:" + old_b + " b:" + b Flip Wend |
| ||
You need to give old_r, old_g and old_b new values once u've faded to the new color... otherwise r will stay equal to old_r and keep resetting the counter to 0. Actually that wasn't the only problem.. I modified the code some to make it work right: Graphics3D 800,600,32,2 SeedRnd MilliSecs camera = CreateCamera() light = CreateLight() old_r = Rnd(0, 255) old_g = Rnd(0, 255) old_b = Rnd(0, 255) r = Rnd(50, 255) g = Rnd(50, 255) b = Rnd(50, 255) CameraClsColor camera, old_r, old_g, old_b Global counter=0 While Not KeyDown( 28 ) If r < old_r r = r + 1 ElseIf r > old_r r = r - 1 Else counter = counter + 1 EndIf If g < old_g g = g + 1 ElseIf g > old_g g = g - 1 Else counter = counter + 1 EndIf If b < old_b b = b + 1 ElseIf b > old_b b = b - 1 Else counter = counter + 1 EndIf If counter = 3 counter = 0 old_r=Rnd(50, 255) old_g=Rnd(50, 255) old_b=Rnd(50, 255) EndIf CameraClsColor camera, r, g, b UpdateWorld RenderWorld Text 1,1,"counter:" + counter + " old_r:" + old_r + " r:" + r + " old_g:" + old_g + " g:" + g + " old_b:" + old_b + " b:" + b Flip Wend |
| ||
this works fine until r= 211, g = 200 and b = 51. then it stops. Ran it several times, but it keeps stopping at those esact colours |
| ||
Yeah I think "counter = 3" should be changed to "counter > 500". Works here now. |
| ||
Oops, I think I left my brain somewhere other than my head yesterday :S. Here's how to do it in a way that works correctly:Graphics3D 800,600,32,2 SeedRnd MilliSecs camera = CreateCamera() light = CreateLight() old_r = Rnd(0, 255) old_g = Rnd(0, 255) old_b = Rnd(0, 255) r = Rnd(50, 255) g = Rnd(50, 255) b = Rnd(50, 255) CameraClsColor camera, old_r, old_g, old_b While Not KeyDown( 28 ) If r < old_r r = r + 1 ElseIf r > old_r r = r - 1 Else rDone = True EndIf If g < old_g g = g + 1 ElseIf g > old_g g = g - 1 Else gDone = True EndIf If b < old_b b = b + 1 ElseIf b > old_b b = b - 1 Else bDone = True EndIf If rDone = True And gDone = True And bDone = True rDone = False gDone = False bDone = False old_r=Rnd(50, 255) old_g=Rnd(50, 255) old_b=Rnd(50, 255) EndIf CameraClsColor camera, r, g, b UpdateWorld RenderWorld Text 1,1,"old_r:" + old_r + " r:" + r + " old_g:" + old_g + " g:" + g + " old_b:" + old_b + " b:" + b Flip WendOf course, the best way would be to only check the Red colour and then just set the Green and Blue colours based on the Red colour using an Interpolate() function. That way all 3 values will reach the target colour at the same time. |
| ||
Of course it would be better still to initialise r_done, g_done and b_done to false at the start! Have you found your brain yet ;-) |
| ||
It's not really necessary to initialise the variables in such a simple app :P |