Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Adopting a colour underneath.

  • Adopting a colour underneath.

    Posted by Neal Coghlan on May 18, 2010 at 3:19 pm

    Hello all,

    I was wondering if it’s possible to have a shapes adopt the colour of another object/comp/photo (in a similar way to how particular can sample a colour underneath) via an expression. I have a grid of triangles that I’d like to change colour and opacity dependant on a ribbon of colour in a hidden comp that would sit below. In a way it would be like a triangular pixellation effect.

    Many thanks,
    Neal

    Barry Suydam replied 14 years, 4 months ago 3 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    May 18, 2010 at 4:58 pm

    You can use sampleImage() to sample the color of another layer. So you could apply the Fill effect to your triangles and use an expression like this for the Color parameter:

    target = thisComp.layer(“background”);
    samplePoint = target.fromWorld(toWorld(anchorPoint));
    sampleArea = [width,height]/2;
    target.sampleImage(samplePoint, sampleArea, true, time)

    You can adapt it to work for opacity as well. For example, to use the red channel of your background layer to drive opacity, you could do it like this:

    target = thisComp.layer(“background”);
    samplePoint = target.fromWorld(toWorld(anchorPoint));
    sampleArea = [width,height]/2;
    c = target.sampleImage(samplePoint, sampleArea, true, time);
    c[0]*100

    Dan

  • Neal Coghlan

    May 19, 2010 at 10:08 am

    Hi Dan, thanks for the quick reply.

    I’ve just had a go at trying to use that code – it seems to sample a colour from the image, however I’m not sure whereabouts the sample is being sampled! I’ve tried moving the anchor points and positions around but the colour still stays the same – even reapplying the code after changing values still shows the same colour. Not sure what I’m doing wrong here exactly..

    Cheers!

    Neal

  • Dan Ebberts

    May 19, 2010 at 5:01 pm

    The expression is set up to sample (and average) an area the same size as the layer with the expression. Maybe you need to sample a smaller area. More details about your set up (layer names, dimensions, etc.) would be helpful.

    Dan

  • Barry Suydam

    January 19, 2012 at 6:17 pm

    Dan,
    I am doing something similar, however what I have is white text over a horizontally split white and blue background(sampleImage BG). What I am trying to accomplish is if the portion of text is over white change the color of the text to blue and when the portion of text is over the blue background change it to white. I don’t know how to adapt this expression to do what I want it to do. I think it is close though.

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