The Expressions Thread

Thank you so much felt! :slight_smile:

Hi,
i want to make the width of a rectangular shape easily editable with an expression.

Therefore i have unlinked the size of the rectangle path and now i want to link the size to a slider expression control. My problem is that i don’t know how to change the width only, cause if i move the slider effect now the high gets scaled as well as the width…

I would really appreciate your help, thank’s in advance! :slight_smile:

Leupsi said

Hi,
i want to make the width of a rectangular shape easily editable with an expression.

Therefore i have unlinked the size of the rectangle path and now i want to link the size to a slider expression control. My problem is that i don’t know how to change the width only, cause if i move the slider effect now the high gets scaled as well as the width…

I would really appreciate your help, thank’s in advance! :slight_smile:

add this to your layer scale property:

x = *pickwhip with slider ;(dont forget the semicolon at the end)
y = transform.scale[1];
[x,y]

Thank’s alot Creattive so simple but so useful! :slight_smile:

Leupsi said

Thank’s alot Creattive so simple but so useful! :slight_smile:

kein Problem, immer wieder gern :slight_smile:

InlifeThrill said

Here is something from a while ago. Helped me a lot. Used it again today. I’ll post it here for anyone with similar request:

Q: What if you want to link together effects in different compositions… cc sphere for example, and you want to match ALL of their properties. Should I go one by one and link them all individually or is there a smart way that just makes two effects alike with one line of code.

Answer:

Just what I wanted :slight_smile: Thanks Inlife

How to attach a camera to a null using only expressions.

From my answer to Dsign on another thread…

Dsign was having trouble in CS4. When he parented his camera to a null, CC Particle World was no longer picking up the position of the camera correctly (it works in CS6, btw). I suggested he try attaching an unparented camera to the null using expressions only…

On an unparented camera’s position:

L = thisComp.layer("Null");
L.toWorld(L.anchorPoint);

The orientation’s a bit more difficult. You need to know your way around matrix math and trigonometry if you want to get to the bottom of how this one works… Or you can just paste the following on to the Camera’s Orientation. :slight_smile:

L = thisComp.layer("Null 1");
[Math.atan2(-L.toWorldVec([0,0,1])[1],L.toWorldVec([0,0,1])[2]),Math.asin(L.toWorldVec([0,0,1])[0]),Math.atan2(-L.toWorldVec([0,1,0])[0],L.toWorldVec([1,0,0])[0])]*180/Math.PI;

If Rotation and POI are neutral, it’ll take the same orientation as the null… then you can offset it using POI or Rotation.

You can’t scale a camera, so no need for an expression on the scale.

It can also be written for a parented camera. In other words, to position and orientate the camera to the position and orientation of Null 1, when it’s actually the child of Null 2, but the expression gets a little bit more complicated. Let me know if you’re interested.

Historic thread Felt! Thanks a lot for share it!

How to wiggle a layer at a certain angle

 angle = 45;
 w = wiggle(3,100) - value;
 a = degreesToRadians(angle);
 x = w[0] * Math.cos(a);
 y = w[0] * Math.sin(a);
 value + [x,y]

Edit: Nice. Thanks, Didgi… I’ll link it to the first post.

Or how about the same using a vector instead of an angle?

vec = [1,1];
w = wiggle(3,100) - value;
value + w[0] * vec;

-f.

didgi said

Wiggle position in a certain angle

angle = 45;
w = wiggle(3,100) - value;
a = degreesToRadians(angle);
x = w[0] * Math.cos(a);
y = w[0] * Math.sin(a);
value + [x,y]

Nice. Thanks, Didgi…

Or how about the same using a vector instead of an angle?

vec = [1,1];
w = wiggle(3,100) - value;
value + w[0] * vec;

Expression for a smooth credit roll

Expression for a smooth Credit Roll.Even rate values should be used if you are rendering to an interlaced format

 rate = 2; //value in pix/frame.
 if (marker.numKeys > 0){
     if (time > marker.key(1).time){
         value - [0,rate*timeToFrames(time-marker.key(1).time)];
     } else {
         value;
     }
 }

without layer marker

 rate = 2; //value in pix / frame.
 value - [0, rate*timeToFrames(time)];

How to make a squish and squash expression with layer markers

squish and squash expression with layer markers

Thanks, Didgi… I took the liberty of compacting the code a little, and adding thisLayer (not for compactness, but for clarity). I also added an option 2 that uses wiggle instead of sine to add a non-uniform noise-based squish/squash effect.

Use on position or scale (or other Array(2) property) What this expression does is make the layer move around each time it passes a layer marker. Or scale up and down if you put it on scale.

There’s a bit of a harsh jump at the markers. Maybe there’s a way to sort that out with an ease function too.

-felt.

 amp=20; // max amplitude in pixels
 freq=1; //oscillations / second
 decay=10; //how fast it slows down
 n = null;

 if (marker.numKeys > 0){
     n = thisLayer.marker.nearestKey(time).index;
     if (thisLayer.marker.key(n).time > time) n--;
 }

 if (n){
      t = time - thisLayer.marker.key(n).time;
      //option 1
      newVal = amp*Math.sin(freq*2*Math.PI*t)/Math.exp(decay*t); value+[newVal, newVal];
      //option 2 (comment out to use option 1)
      newVal = (wiggle(freq, amp)-value) / Math.exp(decay * t); value + newVal; 
 } else {
      newVal = value;
 }

Auto Fade Expression

Add to the Opacity property.

Edit: Just to add a little description of what it does: This fades a layer in and out. You can use two markers. If you do, then the layer will fade in from the in-point to the first marker and will fade out from the last marker to the out-point of the layer. If you don’t use markers, the fade in and out times will depend on the “transition” variable. The fade is linear. You could change this by changing the linear function to ease, easeIn or easeOut. -felt

var t = time, iPt = inPoint, oPt = outPoint; //shorthand to keep the code shorter
var transition = 20; // transition time in frames if no markers used
if (marker.numKeys >= 2){ //markers version
   linear(t, iPt, marker.key(1).time,0,100)-linear(t, marker.key(2).time, oPt, 0, 100);
} else { //no markers version
    tSecs = transition * thisComp.frameDuration; // convert to seconds
    linear(t, iPt, iPt + tSecs, 0, 100) - linear(t, oPt-tSecs, oPt, 0, 100);
}

Also, there’s a slightly more robust version here

Jumpy Wiggle (makes wiggle skip and hold rather than move fluidly)

// Jumpy Wiggle (moves at a random FPS)
v=wiggle(5,50);
if(v < 50)v=0;
if(v > 50)v=100;
v

Move at a constant speed without keyframes.(x-axis)

 veloc = -10; //horizontal velocity (pixels per second)
 x = position[0] + (time - inPoint) *veloc;
 y = position[1];
 [x,y]

for rotation.

// Spin (rotate at a constant speed without keyframes)
 veloc = 360; //rotational velocity (degrees per second)
 r = rotation + (time - inPoint) *veloc;
 [r] ;

I have a comp called ‘main’. With in the ‘main’ comp I have ‘ph1’ composition. It contains some Fx & Animations. In Project Panel I organize both comps in a folder called ‘Scene1’.

If I Duplicate the ‘Scene1’ folder I got new ‘Scene2’ folder. The new ‘main’ comp contains old ‘ph1’ comp. But When I duplicate like this the new ‘main’ comp must contain ‘ph1’ and it should contains all Fx & Animation. Is there any Script/Exp available for this??
I hope you Understand my problem :|.

DarkLand said

I have a comp called ‘main’. With in the ‘main’ comp I have ‘ph1’ composition. It contains some Fx & Animations. In Project Panel I organize both comps in a folder called ‘Scene1’.

If I Duplicate the ‘Scene1’ folder I got new ‘Scene2’ folder. The new ‘main’ comp contains old ‘ph1’ comp. But When I duplicate like this the new ‘main’ comp must contain ‘ph1’ and it should contains all Fx & Animation. Is there any Script/Exp available for this??
I hope you Understand my problem :|.

not sure if I have understood you correctly. You want the new main2 comp to contain the new ph2 comp, right?

use this script: http://aescripts.com/true-comp-duplicator/

Creattive said

not sure if I have understood you correctly. You want the new main2 comp to contain the new ph2 comp, right?

use this script: http://aescripts.com/true-comp-duplicator/

Yes.

Thank you very much :slight_smile:

@DarkLand: you’re welcome :slight_smile:

I have a question, too:

Is it possible to change only a specific keyframe in an animation?

I have a layer that’s color is animated from green to blue. For this I have 2 keyframes. I want that you can easily change one of these colors, without having to look for the keyframes, so for example:

animation from green > red.

or

animation from red > blue

So is it possible that I have a control-layer with 2 color pickers, one for each keyframe?

Is it possible to change only a specific keyframe in an animation?

Creattive said

Is it possible to change only a specific keyframe in an animation?

I have a layer that’s color is animated from green to blue. For this I have 2 keyframes. I want that you can easily change one of these colors, without having to look for the keyframes, so for example: animation from green > red … or … animation from red > blue.

So is it possible that I have a control-layer with 2 color pickers, one for each keyframe?

Not really… well not simply, anyway. But there is a way to achieve what you want to do.

col1 = Comp("x").layer("y").effect("z")(1).value;//ref to color effect
col2 = Comp("x").layer("y").effect("z2")(1).value; //ref to other color effect
if(thisProperty.numKeys >= 2) {
     key1time = thisProperty.key(1).time;
     key2time = thisProperty.key(2).time;
     if(time>=key1time && time<= key2time) {
          elapsed = (time-key1time)/(key2time-key1time);
          elapsed = ease(elapsed, 0, 1, 0, 1); //optional if you want it eased
          tCol = elapsed*col2 + (1-elapsed)*col1;
     } else if(time> key2time) {
          tCol = col2;
     } else {
          tCol = col1;
     }
} else {
     value;
}