Skip to main content
Inspiring
November 22, 2024
Question

Distribute lines evenly based on gap instead of position

  • November 22, 2024
  • 1 reply
  • 1159 views

I have a rig set up where I can have a stack of line layers all parented to a control layer which allows me to set the 'top' and 'bottom' layers of the stack and then have the middle layers linearlly interpolate the line shape, position, color, and stroke weight. This is nice because it allows me to create one shape layer, apply an effect preset, and then simply duplicate the layer to make the blended array. It works and looks great as long as the top and bottom lines are the same weight. If there is an increase, the spacing starts to look funny as it's just a linear distribution of each layer's position rather. What I'm trying to do is update the position calculation's expression to adjust for a difference in line thickness. 

 

Using Illustrator and rectangles instead of lines, I've identified a pattern in the difference between a center-based distribution and a gap-based distribution. The difference in distribution increases at a predictable rate to the center of the layer stack and back down at the same rate, so the distribution would be the same regardless of whether the top or bottom stroke is thicker.

 

However, I cannot figure out how to translate the math I'm doing on paper to an Ae expression, but it's the type of thing that seems like there is a way to do it. The calculation is: 1/2 the number of center layers*weight increase for the first middle layer and then each subsequent layer is the previous increase value + the difference between that value and the prior one - the weight increase until the middle where it starts going back down.

 

I don't think I explained that well, so here is an example (also see attached image):
For a 9-layer stack where the top has a thickness of 10 and the bottom is 90 (an increase of 10pt between each layer), the gap-based distribution would be:

  1. No change
  2. 35px up (10pt weight increase * [7 middle layers/2] )
  3. 60px up (35 from the previous increase + 25)
  4. 75px up (60 from the previous increase + 15)
  5. 80px up (75 from the previous increase + 5)
  6. 75px up (80 - 5)
  7. 60px up (75 - 15)
  8. 35px up (60 - 25)
  9. No change (also 35 - 35)

 

This pattern's calculation is the same regardless of the number of layers or the amount of the weight increase. But recognizing that pattern and getting the computer to calculate it are not the same thing.

 

I've been able to calculate the weight increase, what the gap should be, and how far away each layer's index is from the center of the stack. That feels like it should be enough to figure this out by moving the layer from its linear distribution, but it just isn't working.

 

Is there an easier way to do this?

1 reply

Mylenium
Legend
November 22, 2024

The actual spacing is just the base spacing plus half the thickness of the start line of a segment and the same for the end line. The rest is just based on index-1 or index+1 type calculations, so I'm not sure what the problem is. You may just need to construct a loop to add up all values for any given index and you may also need to calculate those values first to determine what the real available free space in-between start and end is.

 

Mylenium

Inspiring
November 22, 2024

I've used the index+/- expression a bunch of times to get transform properties from other layers to use in calculations, but for some reason I keep getting an error with this one. (I don't recall the exact text of the error, but I do remember that it didn't seem to make sense). 

Again, I've used thisComp.layer(index+1) or (index-1) a ton in the past and never had problems with it.

 

The strange thing is that the expression works just fine if I'm basing the spacing on one layer and then entering what I want the gap to be. The problem occurs when I want to space the layers out by changing the position of the top and bottom layer (instead of just adjusting what the gap is). For some unknown reason, the expression breaks when I have the gap as a calculated value instead of an entered value. 

Dan Ebberts
Community Expert
Community Expert
November 22, 2024

It would probably help if you shared the expression you're using.