ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Link Color To The Position Of Null

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Kiryla Chilko
Link Color To The Position Of Null
on Jun 13, 2018 at 8:22:48 am

Hi everyone!

Hope you can help me to overcome my AE expression illiteracy 😄

So basically I'm doing some UI demo animation and there's a drop-out menu with font options. I want to make the area of the text option highlighted with light blue when the pointer touches the area of the font option. Pretty common stuff so to say.

There are 12 options total, so I have 12 rectangles underneath. When inactive, they're whtite, when I position a null (the null I'll attach the cursor to) over them, they're becoming blue, that's it.

I used an expression like this for the fill effect:

p1=thisComp.layer("cursor null").transform.position;
p2=transform.position;

s=sub(p2,p1);
l=length(s);

white=thisComp.layer("mask").effect("selectionWhite")("Color");
blue=thisComp.layer("mask").effect("selectionBlue")("Color");

linear(l,25,24.5,blue,white);


It works, but not actually the way I want to. The sub() turns out to calculate the distance between two anchor points. But I have a 250x47 rectange. So if I move my cursor null from vertically straight over the anchor point of the rectangle, it's ok. Yet if I touch left or right edge, it's not working, because as you can see the the radius of color property activation has the diametre of 24.5 pixels around the anchor point of the rectangle.

How can I activate the color property at any point of the rectangle then?


Return to posts index

Dan Ebberts
Re: Link Color To The Position Of Null
on Jun 13, 2018 at 1:19:56 pm

If your rectangles are solids, something like this should work:


p1=thisComp.layer("cursor null").transform.position;
p2=fromComp(p1);

white=thisComp.layer("mask").effect("selectionWhite")("Color");
blue=thisComp.layer("mask").effect("selectionBlue")("Color");

if (p2[0] < 0 || p2[0] > width || p2[1] < 0 || p2[1] > height) white else blue


Dan



Return to posts index

Kiryla Chilko
Re: Link Color To The Position Of Null
on Jun 13, 2018 at 1:35:40 pm

Thank you Dan! I'll test this.

However, how can I make this work with the shape layers (for example, I want to do the same thing with a star or whatever).

Is there a way to show my null's anchor point that this particular point in space is already a shape?


Return to posts index


Dan Ebberts
Re: Link Color To The Position Of Null
on Jun 13, 2018 at 4:29:38 pm

You could try something like this:

p = thisComp.layer("cursor null").transform.position;

white=thisComp.layer("mask").effect("selectionWhite")("Color");
blue=thisComp.layer("mask").effect("selectionBlue")("Color");

if (sampleImage(p,[.5,.5],true,time)[3] > 0) blue else white


Dan



Return to posts index

Kiryla Chilko
Re: Link Color To The Position Of Null
on Jun 13, 2018 at 6:07:39 pm

Thank you!

The first expression for solids works fine, the second one won't work, yet something is better than noting.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]