How to have a randomly changing colour background?

Ed_PerkinEd_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

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772

    You need to set your random number to generate between 0 and 1.

  • SocksSocks London, UK.Member Posts: 12,822

    @jamie_c said:
    You need to set your random number to generate between 0 and 1.

    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.

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772

    @Socks, even better! :)

  • SocksSocks London, UK.Member Posts: 12,822
    edited November 2014

    @HipsterShot said:
    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?

    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

  • Ed_PerkinEd_Perkin Midlands,UKMember Posts: 346

    Thanks @socks This is gonna help! :D 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"

  • BigDaveBigDave Member Posts: 2,239

    @Socks‌
    your a beast man

Sign In or Register to comment.