Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity › Forums › Adobe After Effects Expressions › random movement on grid with specific pixels each movement

  • random movement on grid with specific pixels each movement

    Posted by Danjel Van den hoogen on January 29, 2016 at 1:43 pm

    So i have an expression. With this my blocks are moving randomly on the grid. Perfect…However: I want to move a block 200 pixels each time, instead 200 pixels one time and the other time 200*5 pixels

    So i can lower my grid number to 2, but then i need a new origin on every new layer with a distribution of 200 each
    or
    I need an expression to move each block just 200 in the movement.

    See below what I have

    Can anybody help? Thanks!


    Adobe After Effects 8.0 Keyframe Data

    Units Per Second 25
    Source Width 200
    Source Height 200
    Source Pixel Aspect Ratio 1
    Comp Pixel Aspect Ratio 1

    Transform Position
    Frame X pixels Y pixels Z pixels
    15.5 0 0

    Expression Data
    origin = [0,0]+random(200,200); //upper left hand corner of grid
    dimX = 5; //number of columns
    dimY = 5; //number of rows
    gap = 200; // distance between cells (pixels)
    gridRate = 300; //speed (pixels per second)
    holdTime = 4; //(seconds)

    end = 0;
    j = 0;

    while (time >= end){
    seedRandom(j,true);
    startX = Math.floor(random(dimX))*gap + origin[0];
    startY = Math.floor(random(dimY))*gap + origin[1];
    j +=1;
    seedRandom(j,true)
    start = end;
    endX = Math.floor(random(dimX))*gap + origin[0];
    endY = Math.floor(random(dimY))*gap + origin[1];
    deltaX = Math.abs(endX - startX);
    deltaY = Math.abs(endY - startY);

    end += (deltaX + deltaY)/gridRate + 2*holdTime;
    }

    p1 = start + deltaX/gridRate;
    p2 = p1 + holdTime;
    p3 = p2 + deltaY/gridRate;

    if (time < p1){
    ease(time,start,p1,[startX,startY],[endX,startY])
    }else if (time < p2){
    [endX,startY]
    }else if (time < p3){
    ease(time,p2,p3,[endX,startY],[endX,endY])
    }else{
    [endX,endY]
    }
    End of Expression Data

    End of Keyframe Data

    Kalleheikki Kannisto replied 10 years, 8 months ago 2 Members · 1 Reply
  • 1 Reply
  • Kalleheikki Kannisto

    January 30, 2016 at 7:38 am

    You’ll need to generate an array of coordinates first, as every subsequent coordinate depends on the previous location.

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