This wouldn’t be super easy but not too difficult either; you should look at generating paths with random numbers inside an array, then build an if/or statement that will push coordinates from [X[n],Y[n]] or [X[n-1],Y[n]] whether the point is even or odd to get a right-angles pattern. You might have to figure out a way to step the incremental random numbers to a grid; say, round to the nearest integer and then multiply the offset by a standardized number.
Then add a trim path and a white stroke, that will be the snake layer; look at the stroke for the width, then measure the total length of your randomly generated path. calculate the distance and make a proportion and add that to the end to adjust the length. Keyframe the offset from 0 to 100;
Then make another path that grabs the first path and add a very short trim to that and a red stroke, that will be the food. You will need to build a randomized-step based on time that checks if the snake’s offset is equal to this offset for all previous frames, and if it is step forward.
Then to the snake’s trim end, you will need to check again if and when the offset was equal between the head and the food, and when it is add one incremental end equal to the width of the snake stroke.
I’ve stuck some code to the bottom for as far as I took this; this is for generating the path. After this, you’re on your own.
function splitArray(Arr){ //function to seperated X and Y coordinates;
a = []; b = [];
for (i=0;i<Arr.length;i++){
a[i] = Arr[i][0];
b[i] = Arr[i][1];
}
return [a,b];
}
S = 1; //flips the direction of the split;
Astart = [-100,100]; //the start point
Aend = [2000,900]; //the end point
Aseed = 12345; //a random seed
Anum = 8; //number of turns the snake will take
A=[Astart]; //creates array
seedRandom(Aseed,true);
for(i=0;i<Anum;i++){
//BUILD THE STEPPER CODE HERE
A.push(random(Astart, Aend));
}
//splits the array into X and Y coordinates;
splitA = splitArray(A);
Xcor = splitA[0];
Ycor = splitA[1];
P = [];
i = 1;
//offsets the coordinates to X/Y right angles based on even/odd calcs
while(i<A.length){
if(P.length % 2 == 0)
J = [Xcor[i-(S==1?1:0)],Ycor[i-(S!=1?1:0)]];
else{
J = [Xcor[i] ,Ycor[i]];
i++;
};
P.push(J);
}
createPath(P,[],[],false)
Alex Printz
Mograph Designer