Activity › Forums › Adobe After Effects Expressions › limited random value generator with keyframes
-
limited random value generator with keyframes
Posted by Jack Rudy on February 22, 2017 at 3:16 amI would like to have a random value generator that chooses between only specified values such as (-4,-3,-2,-1,0,1,2,3,4) or (23,2,9,-13), I would also like it to choose a new value every 20 keyframes. bonus points if you can tell me how to do it where some values appear more often than others.
Jack Rudy replied 9 years, 6 months ago 2 Members · 6 Replies -
6 Replies
-
Dan Ebberts
February 22, 2017 at 6:15 amThis would be my general approach:
f = 20; // frames
myArray = [23,2,9,-13];
seg = Math.floor((time-inPoint)/framesToTime(f));
seedRandom(seg,true)
myArray[Math.floor(random(myArray.length))];Weighting is a little trickier. A simple method would just be to put certain values in the array multiple times.
Dan
-
Jack Rudy
February 22, 2017 at 11:14 amThis is very close to what I wanted but is there any way I can have the numbers change continuously. to be more specific my object jumps from one place to another right now, but I would like it to travel to those places rather than teleport.
-
Dan Ebberts
February 22, 2017 at 2:23 pmSomething more like this maybe:
f = 20; // frames
myArray = [23,2,9,-13];
d = framesToTime(f);
seg = Math.floor((time-inPoint)/d);
t = (time-inPoint)%d;
seedRandom(seg+1,true);
v2 = myArray[Math.floor(random(myArray.length))];
seedRandom(seg,true);
v1 = myArray[Math.floor(random(myArray.length))];
linear(t,0,d,v1,v2)Dan
-
Jack Rudy
February 22, 2017 at 6:45 pmThis worked very well, thank you. bonus question: is there a way to limit how rapidly the values rise and sink? more specifically, I would rather it not jump from 0 to 360 immediately, so can I limit it to only change a maximum of ±180 at a time? I’m fine if this is not possible.
-
Dan Ebberts
February 22, 2017 at 7:29 pmSo are you saying that at each 20 frame boundary, the value might land on something other than an entry in the array? I’m sure you can get the behavior you want, but you might need a different approach than what we have so far.
Dan
Reply to this Discussion! Login or Sign Up