Domino Expression

Moderators: Disciple, zlovatt

Post Reply
kobyg
Posts: 128
Joined: December 7th, 2007, 10:11 am

Here is an expression I wrote that makes pictures drop like domino pieces falling on each other.
You should apply this expression to the xRotation property of a sequence of 3D layers (pictures) that are distributed in the Z-axis. The Anchor point of each layer should be at the bottom of the later.
The expression checks automatically the height of each picture and the distance between adjacent pictures to make the movement accurate and independent of the pictures' size and spacing. You can put as many pictures as you want.

Code: Select all

pi = Math.PI;
D = length(transform.position,thisComp.layer(index+1).position);
H = thisLayer.height;
a1 = -Math.asin(D/H)*180/pi;
b = thisComp.layer(index+1).transform.xRotation;
a2 = b - Math.asin(D/H*Math.cos(b/180*pi))*180/pi;
T = 1;
t = time - index*T;
(t<=0) ? 0 : ( (t<=T) ? linear(t,0,T,0,a1) : a2)
For the last layer give the following, slightly different, expression:

Code: Select all

T = 1;
t = time - index*T;
(t<=0) ? 0 : linear(t,0,2*T,0,-90)
The T variable controls the speed of the animation (this is the time one domino "piece" falls until it touches the next "piece").

I've attached a Project File that uses this expressions for a sequence of white solids, that are distributed in Z-depth (using a Position expression), and includes some lights and couple of cameras:
Camera 1: Shows the animation from a distance.
Camera 2: Uses an expression to move the camera and follow the domino movement.
Start with Camera 1 to see the behaviour, and then switch Camera 1 off to see the more interesting movement of Camera 2.
The lights also follow the domino movement using an expression.

You can use the Null 1 object to control the animation:
T - controls the speed of the animation
dt - controls the spacing between the pictures (don't put more than 1.18 or the pictures will be too far from one another to make a contact when they fall, and expression will go crazy...)
Domino Animation.zip
(12.46 KiB) Downloaded 3958 times


Enjoy !
Koby.
Rhett
Posts: 1
Joined: August 15th, 2008, 6:14 am

Thanks - this is great!
I tried using this with a few short video clips, and it throws a divide by zero error in line 6 - I have a LOT of stills, so this will be very useful, but... any ideas?
kobyg
Posts: 128
Joined: December 7th, 2007, 10:11 am

My guess is that you have used images/clips with Height smaller than the distance between the images.
That would result in a divide by zero error, because the image's height must be higher than the distance to the next image in order to touch it when it falls, otherwise the expression formula would not have a solution and AE would result a divide by zero error...

The height of the images in my file is currently 900 pixels, and the current distance is 763 pixels.
If you used images/clips smaller than 763 in height, that would result in an error.
In order to change the distance between the images to fit your images/clips, change the value of the "dt" slider control in the NULL 1 object. I would start with dt=0.5, replace the pictures to your own pictures, and then increase the "dt" value to something you like (if you images are smaller than 382 pix in height, start with smaller dt).

p.s.: Once the divide by zero error occurs, AE won't recalculate again, even if you changed the "dt" value, until you click the (=) sign near the expression. You'll have to click each expression individualy, I don't know how to tell AE to recalculate all expressions again... That's why I would recomend to change the "dt" value, BEFORE you replace the pictures.

Hope that helps.
kobyg
Posts: 128
Joined: December 7th, 2007, 10:11 am

Here is a modified expression for the domino effect, that solves the "divide by zero" error, in case the distance between pictures is bigger than images' height. In that case, the "domino pieces" would fall each one at it's own turn instead of trigerring the fall of each other, but this way it will not crash, so you would be able to change the distance between pictures without risking a "divide by zero" error.

Just replace the currect xRotation expression with this one (for all pictures, except for the last one):

Code: Select all

pi = Math.PI;
D = length(transform.position,thisComp.layer(index+1).position);
H = thisLayer.height;
if (D<H){
a1 = -Math.asin(D/H)*180/pi;
b = thisComp.layer(index+1).transform.xRotation;
a2 = b - Math.asin(D/H*Math.cos(b/180*pi))*180/pi;
}else{
a1 = -90;
a2 = -90;
}
T = thisComp.layer("Null 1").effect("T")("Slider");
t = time - index*T;
(t<=0) ? 0 : ( (t<=T) ? linear(t,0,T,0,a1) : a2)
Any comments about the animation would be appreciated !
Koby.
ccf
Posts: 16
Joined: August 21st, 2008, 8:41 am

Koby>

Nice animation. I was looking for something like this some time ago for a tv spot, but very dificult to do by keyframes.
Let me ask you a question, using expressions, how can I have the same footage I replaced by the solid, at the front and at the back in every layer, like a mirror, in order to fly with a camera around the comp and get also image at the back, obtaining a good 3D realistic movement.

Thanks in advance for your time.

and again , nice work !!!!
kobyg
Posts: 128
Joined: December 7th, 2007, 10:11 am

ccf,
Just add a light source, lighting the back side of the images, and you will be able to see them from that side.

If you want that lights source just to light the back side of the images and not change the current shadows of the animation, turn off "Cast Shadows" for that light source.
ccf
Posts: 16
Joined: August 21st, 2008, 8:41 am

Hi Koby:

Great idea !!!!!!!!!!! I will play with the composition and the new light , later I will let you know.

Anyway thanks for your support
ccf
Posts: 16
Joined: August 21st, 2008, 8:41 am

Koby:

I was playing with the light as an ambient, and I got wonderful results flying all over the composition.
That was the mirror effect I was looking for.

Thanks again for your support.

Bye bye
jameswicks

Koby,

Very nice animation.

The issue that I have is that I would like the last domino NOT to fall over, but rather stay standing.
Does your modified expression solve this issue?

And is the modified expression applied to only the last layer, or all the layers?

Thanks,
James Wicks
kobyg
Posts: 128
Joined: December 7th, 2007, 10:11 am

Hi James,

Thank you very much, I'm glad you've liked the animation :)

You'd better apply my modified expression to all layers except the last one (it prevents them from making an error, in case you enter wrong parameters in the sliders).

If you want to leave the last domino standing, just dissable the xRotation expression of the last domino layer (delete it or disable it at the (=) button),
and that's it !

Koby.

p.s.: Sorry for not answering sooner, I got married and went for a honeymoon, very far from home ... 8)
Post Reply