ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Expression to make one shape mimic another's scale & position?

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Henry Acteson
Expression to make one shape mimic another's scale & position?
on Jan 23, 2018 at 3:14:12 am

Okay so I make templates to be used in after effects through the use of Dataclay so one of the big factors in what I do is making sure things stay uniform as information and values within the projects are adjusted before exporting. The desired animation I am creating is illustrated in the gif below, now my dilemma arises when I try to get the coloured boxes to adjust scale and position along with their black foreground counterparts.

Gif of animation:


Here is what I am currently working with in terms of expressions-

To adjust black box size:
The first expression needs to be applied to the shape layers position:

t = thisComp.layer("my_text");
tRect = t.sourceRectAtTime(time,false);
tUL = t.toComp([tRect.left,tRect.top]);
tLR = t.toComp([tRect.left+tRect.width,tRect.top+tRect.height]);
tCenter = (tUL + tLR)/2
myRect = sourceRectAtTime(time,false);
myUL = toComp([myRect.left,myRect.top]);
myLR = toComp([myRect.left+myRect.width,myRect.top+myRect.height]);
myCenter = (myUL + myLR)/2
delta = myCenter - tCenter;
value - delta

This expression needs to be applied to the shapes scale within the shape itself’s transform options for scale. Rectangle 1 > Rectangle 1 Path > Size. In my first test I also applied this expression to the shape layers scale:

t = thisComp.layer("my_text");
tRect = t.sourceRectAtTime(time,false);
tUL = t.toComp([tRect.left,tRect.top]);
tLR = t.toComp([tRect.left+tRect.width,tRect.top+tRect.height]);
myRect = sourceRectAtTime(time,false);
myUL = toComp([myRect.left,myRect.top]);
myLR = toComp([myRect.left+myRect.width,myRect.top+myRect.height]);
margin = 10;
[(tLR[0]-tUL[0] + 2*margin)/(myLR[0]-myUL[0]),(tLR[1]-tUL[1]+ 2*margin)/(myLR[1]-myUL[1])]*100

And my expression to control the coloured boxes behind which are referencing an adjustment layer with Slider Control. They have both the size adjustment expressions as well as this expression:
wiggle(10, thisComp.layer("Slider 1").effect("Slider Control")("Slider"))

I've been using after effects professionally since March of 2017 and largely learnt much of this from this site. It is my first time posting so please let me know if I have left out any necessary information. I should also note that the actual desired template only has single lines of text.

t = thisComp.layer("my_text");
tRect = t.sourceRectAtTime(time,false);
tUL = t.toComp([tRect.left,tRect.top]);
tLR = t.toComp([tRect.left+tRect.width,tRect.top+tRect.height]);
tCenter = (tUL + tLR)/2
myRect = sourceRectAtTime(time,false);
myUL = toComp([myRect.left,myRect.top]);
myLR = toComp([myRect.left+myRect.width,myRect.top+myRect.height]);
myCenter = (myUL + myLR)/2
delta = myCenter - tCenter;
value - delta
wiggle(10, thisComp.layer("Slider 1").effect("Slider Control")("Slider"))


Return to posts index

Andrei Popa
Re: Expression to make one shape mimic another's scale & position?
on Jan 23, 2018 at 9:32:24 am

So i guess what you are saying is that you want to use wiggle plus the position expression for the coloured rectangles. You can not have two values for an expression. After effects just takes the last value. So the first thing that came to mind was to add the wiggle to the expression on the previous line. Did that, but it moved the shape out of my screen. Wondering why it did that, i tried figuring how wiggle works. So aparently wiggle takes the raw value of the position and plays with them. Just substract the position value at the end. It seems to work. So the whole expression would be this.
t = thisComp.layer("my_text");
tRect = t.sourceRectAtTime(time,false);
tUL = t.toComp([tRect.left,tRect.top]);
tLR = t.toComp([tRect.left+tRect.width,tRect.top+tRect.height]);
tCenter = (tUL + tLR)/2
myRect = sourceRectAtTime(time,false);
myUL = toComp([myRect.left,myRect.top]);
myLR = toComp([myRect.left+myRect.width,myRect.top+myRect.height]);
myCenter = (myUL + myLR)/2
delta = myCenter - tCenter;
value - delta+wiggle(10, thisComp.layer("Slider 1").effect("Slider Control")("Slider"))-transform.position


Andrei
My Envato portfolio.


Return to posts index

Henry Acteson
Re: Expression to make one shape mimic another's scale & position?
on Jan 23, 2018 at 10:18:43 pm

Andrei,

Thank you ver much for helping me out with this. That new expression has fixed my issue.

Regards,
Henry


Return to posts index

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