• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Tweaking a Dan Ebberts expression: How to resolve a shape's random motion to its initial position?

New Here ,
Feb 28, 2022 Feb 28, 2022

Copy link to clipboard

Copied

Hi there -

 

I'm new to AE and am working on learning expressions by looking at existing expressions and tweaking them to understand how they operate.

 

I've been playing with one of Dan Ebberts's expressions to randomize motion of a shape in a comp and am wondering if there is a way to make the shape's "end position" at the conclusion of the timeline resolve to the shape's initial position (to create a seamless loop).

 

Any suggestions or tips on resources that might address this would be very welcome. Thank you!

 

Here is the expression of Dan's I've been working with:

 

moveMin = .3; //minimum move time

moveMax = .5; //maximum move time

 

pauseMin = .2; // minimum pause time

pauseMax = .5; // maximum pause time

 

minVal = [0*thisComp.width, 0*thisComp.height];

maxVal = [1*thisComp.width, 1*thisComp.height];

 

seedRandom(index,true); // set pre-run for endT

endT = - random(moveMax);

 

j = 0;

k = 0;

while ( time >= endT){

j += 1;

seedRandom(j,true);

startT = endT;

if (j%2){

endT += random(moveMin,moveMax);

k++;

}else{

endT += random(pauseMin,pauseMax);

}

}

if (j%2){

seedRandom(k,true);

endVal = random(minVal,maxVal);

seedRandom(k-1,true);

startVal = random(minVal,maxVal);

ease(time,startT,endT,startVal,endVal)

}else{

seedRandom(k,true);

random(minVal,maxVal)

}

TOPICS
Expressions , How to

Views

204

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 28, 2022 Feb 28, 2022

Copy link to clipboard

Copied

I'm sure it could be done, but it's tricky becuase the move and pause times are all random, so you could end up with a really short duration at the end of the comp to get back to the starting point. Also, since the animation has a random pre-run, calculating where the layer needs to be at the end of the comp would be tricky. You might need a more predictable approach...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 28, 2022 Feb 28, 2022

Copy link to clipboard

Copied

Ah, ok! Thank you for taking the time to consider the idea - and glad to hear from you that it definitely is as tricky as I've been finding it! Thanks for all your resources, too, Dan. I appreciate it! Very helpful and instructive.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 01, 2022 Mar 01, 2022

Copy link to clipboard

Copied

Actually it's not that difficult at all. You just need to substitute the range values in the random functions for arrays such as random([0,3,4,7,9,6]). That way you can

 

a) determine a fixed end value that equates one from the array and

b) have some calculation that defines a criteria how many random values there need to be before reaching the final value

 

This can all be done by measuring the .length ofthe array and shuffling the data around or pushing it into a new, pre-sorted array from which it is read linearly, including the option to just have the first and last values be the same. That and of course there's a million other ways to do it like actually defining a start and end keyframe and only having the stuff inbetween be random. It's still a lot of code, but certainly all possible, just not directly with the code above.

 

Mylenium

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 01, 2022 Mar 01, 2022

Copy link to clipboard

Copied

LATEST

Ah, thank you! I'll give this a shot. Appreciate it!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines