Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Changing color of a light randomly with expressions

  • Changing color of a light randomly with expressions

    Posted by Helgi Johannsson on August 28, 2005 at 9:12 pm

    Hi,

    I’m somewhat familiar with expressions, but this leaves me with no clue. How can I randomly change color of a light with expressions. Change maybe every half a second or so. And I would certainly prefer only to use 5-6 colors.

    Is this possible?

    Helgi Johannsson replied 20 years, 8 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    August 28, 2005 at 10:27 pm

    In expressions, color is represented as an array of [red,green,blue,alpha] where the values have to be between 0 and 1. (Leave the alpha value set to 1 – it doesn’t do anything but it has to be there. So this would be one way to change the color at random every half second:

    
    
    period = 0.5; // change color every .5 seconds
    colors = [[1,0,0,1], // red
              [0,1,0,1], // green
              [0,0,1,1], // blue
              [1,0,1,1], // magenta
              [1,1,0,1], // yellow
              [0,1,1,1]] // cyan
    
    seed = Math.floor(time/period);
    seedRandom(seed,true);
    idx = Math.floor(random(colors.length));
    colors[idx]
    
    

    Dan

  • Helgi Johannsson

    September 2, 2005 at 4:46 pm

    Thank you very much Dan, you are incredible 🙂

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy