Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions color array with random hold time

  • color array with random hold time

    Posted by Juanluis Vich on July 19, 2017 at 2:01 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!!

    Juanluis Vich replied 8 years, 9 months ago 3 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    July 19, 2017 at 5:35 am

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

    Dan

  • Juanluis Vich

    July 19, 2017 at 11:24 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

  • Santi Agustí

    July 19, 2017 at 11:47 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];

  • Dan Ebberts

    July 19, 2017 at 1:10 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

  • Juanluis Vich

    July 20, 2017 at 2:37 pm

    thanks!! it works like a charm!

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