How to have a randomly changing colour background?
Ed_Perkin
Midlands,UKMember Posts: 346
Just to change colours randomly bu gradually , tried interpolating every 2 seconds to random green random(1,255) etc but won't work and just goes white , any suggestions?
Comments
You need to set your random number to generate between 0 and 1.
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page
Random (0,1) will give you just 8 colours (out of a possible 16,777,216).
You can access all 167,77,216 colours with random(0,255)/255.
@Socks, even better!
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page
Interpolate Red to random(0,255)/255
Interpolate Blue to random(0,255)/255
Interpolate Green to random(0,255)/255
This will give you the full 24bit range, but you might want to clip the lower and upper extents to avoid pure black or pure white . . . something like this . . . .
Interpolate Red to random(40,255)/255
Interpolate Blue to random(0,200)/255
Interpolate Green to random(40,255)/255
Alternatively you could have the colours slowly cycle through the spectrum (so you don't get any dull colours or pure black or white . . .
Constrain Red to 0.5 *sin( game.Time *50)+0.5
Constrain Green to 0.5 *sin(( game.Time *50)+120)+0.5
Constrain Blue to 0.5 *sin(( game.Time *50)+240)+0.5
An even brighter spectrum with the top and bottom of each channel clipped . . . .
Constrain Red to sin( game.Time *50)+0.5
Constrain Green to sin(( game.Time *50)+120)+0.5
Constrain Blue to sin(( game.Time *50)+240)+0.5
Thanks @socks This is gonna help! Might use this one or the next one aha :
"Interpolate Red to random(0,255)/255
Interpolate Blue to random(0,255)/255
Interpolate Green to random(0,255)/255"
@Socks
your a beast man
My Apps
https://itunes.apple.com/de/artist/david-zobrist/id733552276
https://play.google.com/store/apps/developer?id=David+Zobrist&hl=de