Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions An Expression Kind of Like “Random Grid Movement…”

  • An Expression Kind of Like “Random Grid Movement…”

    Posted by Erin Shelby on November 9, 2007 at 1:22 am

    I am trying to write an expression that is similar in result to Ebberts ‘Random Grid Movement’ expression. I’ll state the design goals now:

    1. A small square moves around in a comp at set intervals (once every 1 second), and moves a set distance of 25 pixels, lets say, each time.

    2. The direction it moves in is random, but always at right angles (0, 90, 180, 270). Like in the Ebberts grid expression..;

    3. I would also like a very strong ‘ease’ movement to at the start/end of the movement.

    4. The part I’m having the most concern with (that I haven’t even really thought about yet) is that I’d like a ‘line’ that follows the square … essentially a very very very tight knit “trail” that fades off. I know from past attempts that the speed of the square will make using a simple ‘echo’ expression difficult to manage (it won’t be a solid line and will have gaps during moments of high velocity).

    —-

    I don’t expect any of you to be able to crack this, so I’m going to post results as I go along if I can nail something close to it. Thanks for reading and if anyone can recommend any areas I should look into it would be apprecaited.

    -Erin

    Edit: I should note that I’m trying to make the square not leave the comp area, also.

    Colin Braley replied 18 years, 6 months ago 2 Members · 1 Reply
  • 1 Reply
  • Colin Braley

    November 9, 2007 at 5:58 am

    I don’t have much time to work on this one…I’ve got a test in the morning…but heres some code to get you started. It’s not very elegant, but it works decently:


    minDist = 50;//min movement
    maxDist = 100;//max movement
    dur = 1;//time between movements
    //--
    seedRandom( index , true );
    epsilon = .01;
    accum = thisLayer.position.valueAtTime( 0 );
    timeAccum = 0;
    for( i = 0; i < time ; i += thisComp.frameDuration ){ if( Math.abs( timeAccum - dur) <= epsilon ){ theta = Math.round( random(0,3) ) * (Math.PI / 2 ); dist = random( minDist , maxDist ); disp = [ dist * Math.cos( theta ) , dist * Math.sin( theta ) ]; accum += disp; timeAccum = 0; } timeAccum += thisComp.frameDuration; } //--- accum

    It makes the layer move properly, but it can move out of the comp, you will have to add code to check for that situation.

    ~Colin

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