Shape & Mask Paths

Maintain stroke width

// from campkeyframe
sf = transform.scale[0]/100; ov = value; nv = ov / sf
// for parented shapes
value / length(toComp([0,0]), toComp([0.7071,0.7071])) || 0.001;
// https://battleaxe.tumblr.com/post/101945073972/maintain-stroke-weight-expression

Accessing Shape Property Group and Index

// shape group index
thisProperty.propertyGroup(2).propertyIndex // change num accordingly
// using name as index eg. line_1
parseInt(thisProperty.propertyGroup(3).name.split("_")[1]); // method 1
parseInt(content(1).name.split("_")[1]) // method 2

Effect Group and Index

// effect index
thisProperty.propertyGroup(1).propertyIndex
// number of effects
thisProperty.propertyGroup(2).numProperties
thisLayer("Effects").numProperties
thisComp.layer("layer")("Effects").numProperties// for ref layer

Masks & Paths

Looping paths (loopOut() doesn't work for paths)

Pingpong
cycle
Pingpong
if (numKeys >1 && time > key(numKeys).time){
t1 = key(1).time;
t2 = key(numKeys).time;
span = t2 - t1;
delta = time - t2;
seg = Math.floor(delta/span);
t = delta%span;
valueAtTime((seg%2) ? (t1 + t) : (t2 - t));
}else
value
cycle
if (numKeys >1 && time > key(numKeys).time){
t1 = key(1).time;
t2 = key(numKeys).time;
span = t2 - t1;
delta = time - t2;
t = delta%span;
valueAtTime(t1 + t)
}else
value

Drawing

square
triangle
square
vertices = [[0,0], [100,0], [100,100], [0,100]];
inTangents=[]
outTangents=[]
closed = true;
createPath(vertices,inTangents, outTangents, closed);
triangle
l = 100;
w = 50;
vertices = [[0,0], [-w,l], [w,l]]
inTangents=[]
outTangents=[]
closed = true;
createPath(vertices,inTangents, outTangents, closed);

Archimedes Spiral [1]

path property
path property
// connect to sliders
let w = 1000;
let points = 200;
let steps = 20;
let angle = 0;
let r = w / 2;
let step = (Math.PI * 2) / steps;
let radius = 0;
let vertices = [];
//main
for (i = 0; i < points; i++) {
angle += step;
radius = i / points * r;
x = Math.cos(angle) * radius;
y = Math.sin(angle) * radius;
vertices[i] = [x, y];
}
createPath(vertices, [], [], 0)

Harmonic Motion

sine
squiggly
sine
// var ctrl = thisLayer;
var inc = 1500;
var amp = 300;
var n = 30;
var freq = .5
var seed = 185;
var vertices = [];
var x, y, pt, phase;
seedRandom(seed, true)
var offset = random() * Math.PI * 2
for (i = 0; i < n; i++) {
pt = i / (n - 1);
x = inc * pt
phase = time * freq * Math.PI * 2 + pt * Math.PI
//phase += offset;
y = amp * Math.sin(phase);
//y *= Math.sin(phase / 2);
//y *= Math.sin(phase / 3);
//y += noise(time + pt) * 100;
// create point
vertices[i] = [x, y]
}
createPath(vertices, [], [], 0)
squiggly
// var ctrl = thisLayer;
var inc = 1500;
var amp = 300;
var n = 50;
var freq = .5
var seed = 185;
var r = 0.25;
var vertices = [];
var x, y, pt, phase;
seedRandom(seed, true)
var offset = random() * Math.PI * 2
for (i = 0; i < n; i++) {
pt = i / (n - 1);
x = inc * pt
phase = time * freq * Math.PI * 2 + (pt * Math.PI /r)
// phase += offset;
w1 = Math.sin(phase);
y = amp * w1;
// create point
vertices[i] = [x, y]
}
createPath(vertices, [], [], 0)

Circle

no tangent
w/ tangent
no tangent
var pts = 50;
var a = 500; //radius
var completion = 100 / 100;
var t, x, y;
var vertices = [];
for (i = 0; i < pts; i++) {
t = i / pts * Math.PI * 2 * completion; // element num/ num of elements ;
x = a * Math.cos(t);
y = a * Math.sin(t);
vertices[i] = [x, y]
}
createPath(vertices, [], [], 1)
w/ tangent
w = 500; // width
r = w/2;
ratio = .5523;
t = r*ratio;
vertices = [[r,0],[0,r],[r,2*r],[2*r,r]];
inTangents = [[t,0],[0,-t],[-t,0],[0,t]];
outTangents = [[-t,0],[0,t],[t,0],[0,-t]];
createPath(vertices,inTangents,outTangents,1);

Torus

x=(a+bcosu)cosvy=(a+bcosu)sinvz=bsinux=(a+bcosu)cosv \\ y=(a+bcosu)sinv\\ z=bsinu
var pts = 50;
var u = 1
var v = 10;
var a = 75 // inner radius
var c = 450 // outer radius
var completion = 100 / 100;
var t, x, y;
var vertices = [];
for (i = 0; i < pts; i++) {
t = i / pts * Math.PI * 2 * completion; // element num/ num of elements ;
x = (c + a * Math.cos(v * t)) * Math.cos(u * t);
y = (c + a * Math.cos(v * t)) * Math.sin(u * t);
vertices[i] = [x, y]
}
createPath(vertices, [], [], 1)