Evenly distribute layers while being aware of their alpha?

Moderators: Disciple, zlovatt

Post Reply
neamedia
Posts: 2
Joined: December 3rd, 2011, 4:38 pm

Hello,

I have 5 prerendered Layers (Letters) building the word "RIDER" in my Comp. Each one of them 500x500 pixel resolution with an alpha channel.
I use this expression on their position properties to distribute them on the x-axis (like tracking actual text) with a slider controller (starting Layer has index 2):

transform.position + [(thisComp.layer("Master Controller").effect("Tracking")("Slider")*(index-2)),0]

Now I get an issue with an uneven distribution, because the expression will change the Position of the actual layer (Anchorpoint in the middle), while the rendered Letters have different widths (the "R" is wider than "I" f.e.).
Is there a way to subtact each layers alpha-width before and after the RGB-pixels (all Letters are centered). Can an expression then distribute the Layers, based on their new calculated width?

PS: The with of the prerendered Layers has to be fixed 500x500 unfortunately...

I hope that i could make myself clear here, and that somebody can help my out with an ingenious solution to my issue :-)

Thanks in advance!
Dan Ebberts
Posts: 320
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

This assumes that your letters are consecutive layers, with the leftmost layer being on top. Add a slider named "Width" to all the letters and add this expression to it:

Code: Select all

for (i = width; i >= 0; i--){
  temp = sampleImage([i,thisComp.height/2],[0.5,thisComp.height/2],true,time);
  if (temp[3] > 0) break;
}

for (j = 0; j <= width; j++){
  temp = sampleImage([j,thisComp.height/2],[0.5,thisComp.height/2],true,time);
  if (temp[3] > 0) break;
}

i-j
Add this Position expression to each of the layers except the left-most/top:

Code: Select all

gap = 20;
L = thisComp.layer(index-1);
Lwidth = L.effect("Width")("Slider");
myWidth = effect("Width")("Slider");
L.transform.position + Lwidth/2 + gap + myWidth/2
The left-most layer should now control the position of the others. Adjust the gap variable to get the tracking you want. You may want to convert the expressions on the sliders to keyframes, because those sampleImage() loops can be cpu-intensive.


Dan
neamedia
Posts: 2
Joined: December 3rd, 2011, 4:38 pm

Thank You Dan,

This was very helpful to me -I can now adapt your (ingenious) solution and work on from there... suddenly my brain works again, thanks for the ´push´, I was kinda stuck - but now i dig expressions even more :P

PS: I love your site - if it wasn´t motionscript.com, I would have never tried to understand and use expressions myself.

kind regards,
Theo
Post Reply