ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

# color array with random hold time

FAQ   •   VIEW ALL
 color array with random hold time on Jul 19, 2017 at 2:01:22 am

hi!
having this Dan's expression (used here https://forums.creativecow.net/thread/227/3939)
``` period = 2 holdTime = 0.5; seed = Math.floor(time/period); t = time%period seedRandom(seed,true); if ( random() > .5 && t < holdTime) 100 else 0; ```

I'm trying to adapt it so instead of the 100 else 0, it goes thru an array of colors like this, but not sure how to do that
` colors = [[255,205,45,255]/255,[220,20,60,255]/255,[30,144,255,255]/255,];`

any help will be welcome, thanks!!

 Re: color array with random hold timeon Jul 19, 2017 at 5:35:25 am

I'm having a little trouble picturing exactly how you want this to work. Maybe you could describe it a little more.

Dan

 Re: color array with random hold timeon Jul 19, 2017 at 11:24:36 am

oh! sorry for the misinfo!
basically I was trying to achieve getting a random color from an array, and make it hold a few seconds, then jump to another color in the array, and so on

 Re: color array with random hold timeon Jul 19, 2017 at 11:47:31 am

there are a lot of better ways to do this, but this may work :

``` colors = [[255,205,45,255]/255,[220,20,60,255]/255,[30,144,255,255]/255,]; period = 2; holdTime = 0.5; seed = Math.floor(time/period); t = time%period seedRandom(seed,true); cc =Math.floor(random(colors.length)); if ( random() > .5 && t < holdTime) id = cc; else id = 0; colors[id]; ```

 Re: color array with random hold timeon Jul 19, 2017 at 1:10:34 pm

Something like this should work:

colors = [[255,205,45,255]/255,[220,20,60,255]/255,[30,144,255,255]/255,];
period = 3;
seed = Math.floor(time/period);
seedRandom(seed,true);
idx = Math.floor(random(colors.length));
colors[idx]

Dan