ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Simple Expression Request

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
cow
Lauren Roundy
Simple Expression Request
on May 27, 2008 at 4:26:11 pm

At least, I assume it's simple.

I need to show different colored balls passing from left to right and back and forth in my 864x480 comp until they eventually rest in the middle. As they are on the left side of the screen, they need to be "positively charged" so, they simply need to have a "+" symbol showing on top of them. As they get to the right side of the screen, they need to have a negative charge (a "-" symbol should be visible on top of the colored dot or ball). When they stop and rest in the center at the end, they need to have no charge (no symbol should be visible).

Any help would be greatly appreciated! And, if possible, if they can fade between positive to negative as they pass from side to side, that would be the best, but it isn't necessary.


Return to posts index

cow
Alex English
Re: Simple Expression Request
on May 27, 2008 at 5:24:07 pm

To preface, please forgive me if any of these don't work. I don't have AE available at the moment.

To handle the charges, you can create the plus and minus symbols and parent them to the balls, then move them to the same spot over the ball.

To make them fade, you use an expression for opacity that uses their position to determine how transparent they are. They would look something like this:
for positive:

swingwidth = thisComp.width;
halfwidth = swingwidth / 2;
Math.max(((halfwidth - transform.position) / halfwidth), 0) * 100


for negitive:

swingwidth = thisComp.width;
halfwidth = swingwidth / 2;
Math.max((swingwidth - halfwidth - transform.position) / halfwidth), 0) * 100


Those would give you a smooth linear fade in opacity for each of those that should match what you were looking for.

If you were needing to make the balls move, you could either animate them with keyframes, animate with keyframes and loop as necessary with expressions, or if you were going for something more sinusoidal, you could use:

freq = 2; //multiplier to change the speed, set where you need it.
swingwidth = 300; //determines how far out they should move
[(swingwidth * Math.sin(time * freq) + thisComp.width / 2), 240]


That should make it oscillate 600 px from end to end, balanced at the center of the comp.

Once again, I can't test any of those right now, but if those don't work out I can check them out later today.

Good luck.



Return to posts index

cow
Lauren Roundy
Re: Simple Expression Request
on May 27, 2008 at 7:05:22 pm

It didn't work. I'm not good with expressions at all, so I don't understand what the problem is, but I can't get it to work.

You said to parent the "+" text layer to the ball, then past the first exression into the opacity of the "+" layer, right?

If that is the case, it doesn't work.

Thanks for your help, if you have any other suggestions, please let me know.

Oh, how would I do it without the opacity changing?


Return to posts index


cow
Lauren Roundy
Re: Simple Expression Request
on May 27, 2008 at 8:27:44 pm

It didn't work. Any other ideas?



Return to posts index

cow
Kevin Camp
Re: Simple Expression Request
on May 28, 2008 at 1:15:58 am

this may do what you are asking...

create a text layer and hit enter on the numbers pad (basically create an empty text layer).

twirl down the properties for the text layer, then for the text property. add an expression for source text and paste this:

if (position[0] < thisComp.width/2){
"+"
}else{
"-"
}

this will give you a + when the text is on the left half of the screen and a - when on the right half fo the screen.

now enable expressions for the opacity of the the text layer, and paste this into it:

Math.abs(100*(1-((position[0]/(thisComp.width/2)))))

this will dissolve the + and - as they move towards the center of the screen.

now you should be able to parent the text layer to a ball/circle (position as needed) and as the ball moves across the screen the + should dissolve away, then at mid screen the - should start to disolve in. then as it moves back across the screen, the reverse should happen. as the ball stops mid screen no symbol should be visible.

is that what you are looking for?

Kevin Camp
Senior Designer
KCPQ, KMYQ & KRCW


Return to posts index

cow
Lauren Roundy
Re: Simple Expression Request
on May 28, 2008 at 2:37:46 pm

Thanks! That worked great. I tweaked it a bit to match my needs. The only thing that doesn't work is that the layer won't change it's position if it is parented to another layer, so, instead of parenting the text to the ball layer, I parented the ball to the text layer. This causes the expression to work.

Thank you for your help.



Return to posts index


cow
Kevin Camp
Re: Simple Expression Request
on May 28, 2008 at 5:34:27 pm

[Lauren Roundy] "The only thing that doesn't work is that the layer won't change it's position if it is parented to another layer, so, instead of parenting the text to the ball layer, I parented the ball to the text layer."

i overlooked that aspect... good catch and fix.

Kevin Camp
Senior Designer
KCPQ, KMYQ & KRCW


Return to posts index

cow
Kevin Camp
Re: Simple Expression Request
on May 28, 2008 at 6:38:22 pm

not that you probably need this now, but we could have created an expression for the text layer's position that could have drawn the positional dat directly from the ball, and thus have actual comp relative positions for the other expressions to work with...

an expression like this in the position parameter of the text layer would have worked nicely:

xOffset = 0;
yOffset = 20;
add(thisComp.layer(index+1).transform.position, [xOffset,yOffset])

this expression will take the position values directly from the layer below it, so you could just drag the text layer above any layer to attach it to the layer below it. xOffset and yOffset are just some variable to fine tune the alignment of the text layer above the ball layer.

Kevin Camp
Senior Designer
KCPQ, KMYQ & KRCW


Return to posts index

cow
Alex English
Re: Simple Expression Request
on May 29, 2008 at 8:33:38 pm

I found that you can also access the position of the parent layer directly.

Using parent.transform.position will get you the position of the parent layer.

Using this as your position would let you change the sign in the text layer as was suggested, and change the opacity, both while still doing it with a parent relationship, which seems like the cleanest way to handle it.



Return to posts index


cow
Kevin Camp
Re: Simple Expression Request
on May 29, 2008 at 8:58:32 pm

that's a very useful function... i hadn't realized that you could access 'parent' data without naming the specific layer.

thanks, very useful.

Kevin Camp
Senior Designer
KCPQ, KMYQ & KRCW


Return to posts index

cow
Lauren Roundy
Re: Simple Expression Request
on May 29, 2008 at 10:16:06 pm

Thank you all! I used all of your suggestions and it worked great!

It saved me a lot of headache and time.





Return to posts index

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