Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Colour: numlayers/index

  • Colour: numlayers/index

    Posted by Conor Flanagan on March 25, 2020 at 8:39 pm

    Hi all,
    I really didn’t want to have to write this but I’m stuck and the key terms to search with are very vague.

    So I’ve used a version of this expression before on many different projects, but I am now trying to get it to work for colour.
    I want to basically have the lightness of the colour divide among the total layers in a comp.

    So for example 10 layers, the lightness will increase in increments of .1
    And adjust dynamically as more layers are added.

    Now I’ve gotten this work up until I add the *i
    For whatever reason multiplying by the index breaks it. No error though, just reverts to default value. I remove the *i I get the result of 1/n

    Is index broken? Am I broken?

    I created a more hackery way for the job I was doing, but now I just want to know how I was being stupid.

    Cheers all.

    n = thisComp.numLayers;
    i = index;
    h = 0
    s = 0;
    l = (1/n)*i;
    a = 0;
    HSL = [h,s,l,a];
    hslToRgb(HSL);

    Conor Flanagan replied 6 years, 5 months ago 2 Members · 2 Replies
  • 2 Replies
  • Andrei Popa

    March 25, 2020 at 10:06 pm

    This works great on my pc. However, since it is the i that gives you trouble, you can try changing it like this:

    n = thisComp.numLayers;
    h = 0
    s = 0;
    l = index/n;
    a = 0;
    HSL = [h,s,l,a];
    hslToRgb(HSL);

    Andrei
    My Envato portfolio.

  • Conor Flanagan

    March 26, 2020 at 9:27 am

    doh….
    I did restart AE but not the computer.
    Sorry.

    But of course index/n. I was worried about numbers exceeding 1, but you’ll never have more than the total.

    Thank you for the sanity and math check Andrei.

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