Creative Communities of the World Forums

The peer to peer support community for media production professionals.

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 am

    I 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 am

    This 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 am

    This 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 pm

    Something 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 pm

    This 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 pm

    So 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

  • Jack Rudy

    February 23, 2017 at 1:26 am

    thank you for the help dan.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy