-
motion in a grid
Hi,
I have to animate 16 icons displayed in a grid of 4×4 squares in 1080×1080 ratio.I need to move them lets say 3 times. So at 0sec there are in “position 01”. At 01sec they move to “position 02” in 10 frames. At 3sec they moved to “position 03”, etc.
Just to make it clear.. the grid has all the square filled with an icon in each position.
It is just that I don’t want to keyframe everything.
I have tried the script below but it is always at random and the squares are sometimes filled with 2 or 3 icons.
Can you help me.
origin = [10,10]; //upper left hand corner of grid
dimX = 8; //number of columns
dimY = 6; //number of rows
gap = 20; // distance between cells (pixels)
gridRate = 300; //speed (pixels per second)
holdTime = .2; //(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]
}