Skip to main content
Participant
April 4, 2017
Answered

Random scale with equal values for xScale and yScale

  • April 4, 2017
  • 2 replies
  • 9697 views

Hi there,

professional scripters might not think of this to be a problem, but I cannot solve it on my own after hours of trying.

I found a random script on www.motionscript.com (thank you so much Dan, for this great resource, you're awesome!).

The sample for "random motion - more chaotic" is exactly what I need, but for the scale property with same random values for xScale and yScale (so that the random scaling is proportionally). I cannot figure out how to do this. I know I need another variable, but I don't know where.

Actually, I want to have a matrix of dots, each scaling up and down again randomly and independently in size and timing...

This is what I got so far:

segMin = .3;

segMax = .7;

minValX = 100;

maxValX = 200;

minValY = minValX;

maxValY = maxValX;

minVal = [minValX, minValY];

maxVal = [maxValX, maxValY];

seedRandom (index, true);

segDur = random (segMin, segMax);

seed = Math.floor (time / segDur);

segStart = seed * segDur;

seedRandom (seed, true);

startVal = random (minVal, maxVal);

seedRandom (seed+1, true);

endVal = random (minVal, maxVal);

easeOut (time, segStart, segStart + segDur, startVal, endVal);

I'd appreciate someone's help without being to demanding 🙂

Thanks a lot for reading this.

Chris

This topic has been closed for replies.
Correct answer Dan Ebberts

Try it this way:

segMin = .3; 

segMax = .7; 

minVal = 100; 

maxVal = 200; 

seedRandom (index, true); 

segDur = random (segMin, segMax); 

seed = Math.floor (time / segDur); 

segStart = seed * segDur; 

seedRandom (seed, true); 

startVal = random (minVal, maxVal); 

seedRandom (seed+1, true); 

endVal = random (minVal, maxVal);

easeOut (time, segStart, segStart + segDur, [startVal,startVal], [endVal,endVal]);

Dan

2 replies

Participant
April 6, 2017

I understand Dan's correction in the script, but I'd never figured that out on my own... As the variable for startVal and endVal just holds a one-dimensional value you have to evaluate this value in the form of a two-dimensional array... This script works at its best! Just copy and paste it to the scale property (or any other two-dimensional property, or adjust it for another dimension).

As I proceeded I tried to adjust the script so that an object scales up to a random Size (easeIn) then remains in that state for a chosen (or randomly generated) amount of time (might even be 0) and then scales down with the same speed (easeOut) to its original size. The time of each animation should depend on the "scale factor". The more an object is scaled up, the longer the animation must be to make all these dots in the grid appear scaling with the same speed.

Therefore I found another script on Dan's website that comes close to what I belong for, but it seems I still didn't get the clue, how scripting in AE really works. The following script scales an object from a starting value to an ending value, holds this for a while, but then suddenly resets the object to its original size without animation. You might laugh but I nearly tried a whole day to achieve this animation without significant proceeding.

scaleTime = 0.5;
holdTime = 1;

totalTime = scaleTime + holdTime;

segTime = time % totalTime;

startVal = 100;

endVal = 200;

if (segTime % time == 0) {

  easeIn (segTime, 0, scaleTime, value, [endVal,endVal]);

} else {

easeOut (segTime, 0, scaleTime, value, [startVal,startVal]);

}

Can anyone explain, why the following script just resets the scale property after the end of totalTime without any animation? Any idea how to do it "the expert's way"?

Thanks for anything that might get me on track :-)

Chriz

Dan Ebberts
Community Expert
Community Expert
April 7, 2017

I'm not sure what you're going for, but play around with this:

scaleTime = 0.5; 

holdTime = 1; 

     

totalTime = scaleTime + holdTime + scaleTime; 

segTime = time % totalTime; 

     

startVal = 100; 

endVal = 200; 

     

if (segTime < scaleTime){ 

  easeIn (segTime, 0, scaleTime, [startVal,startVal], [endVal,endVal]); 

}else{ 

  easeOut (segTime, scaleTime+holdTime, totalTime, [endVal,endVal], [startVal,startVal]);

}

Dan

Participant
April 10, 2017

Thanks a lot again, Dan! I'll try putting things together and I'll post my final script here if working as intended...
So stay tuned :-)

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
April 4, 2017

Try it this way:

segMin = .3; 

segMax = .7; 

minVal = 100; 

maxVal = 200; 

seedRandom (index, true); 

segDur = random (segMin, segMax); 

seed = Math.floor (time / segDur); 

segStart = seed * segDur; 

seedRandom (seed, true); 

startVal = random (minVal, maxVal); 

seedRandom (seed+1, true); 

endVal = random (minVal, maxVal);

easeOut (time, segStart, segStart + segDur, [startVal,startVal], [endVal,endVal]);

Dan

Participant
April 5, 2017

Thank you very much, Dan!

Exactly what I wanted to achieve within hours of trial and error... I will analyze the difference in code... :-)

ketan patel_10
Participant
April 6, 2017

THANKS dAN..