This works for any polygone. It can be simplified though if you need a regular shape, and it is probably easier to animate the “angle” and the “radius” with aditionnal sliders than to use functions (caps are to see them for afar…)
///////////////////////////////// TWEAKS ///////////////////////////////////////
function ANGLE(t){ // returns an angle in degrees...
return t * 60;}
function RADIUS(angle){ // angle is in radians ...
return angle * 10;}
center = [thisComp.width*0.5, thisComp.height*0.5];
angleList = [0,30, 120,150, 240,270] // degrees, in increasing order, from 0 (included) to 360 (excluded)
/////////////////////////////////////////////////////////////////////////////////////
last = angleList.length-1;
a=ANGLE(time); // use a function as above, or a slider to animate the angle (same for the radius)
n=Math.floor(a/360);
b=a-n*360;
if (b<=angleList[0]){ // < === "less or equal"
a1 = (n-1) * 360 +angleList[last]; a2 = n*360+angleList[0];
}
else if (angleList[last]<=b){
a1 = n * 360 + angleList[last]; a2 = (n+1)*360+angleList[0];
}
else{
idx=0;
while (b>angleList[idx+1]){idx++;};
a1 = n * 360 + angleList[idx++]; a2 = n*360+angleList[idx];
}
a = degreesToRadians(a);
a1 = degreesToRadians(a1);
a2 = degreesToRadians(a2);
P = RADIUS(a1) * [Math.cos(a1), Math.sin(a1)];
Q = RADIUS(a2) * [Math.cos(a2), Math.sin(a2)];
center + linear(a, a1, a2, P,Q)
;