This is a very powerful expression that you can use to drive all kinds of very cool effects! Based on knowledge from The Power of Expression Book 

Tools used

Expression

// Make Layers React to a Mask
// Based on knowledge from The Power of Expression Book 
// https://aescripts.com/the-power-of-expression/
//
// Requires the new 'Javascript' expressions engine introduced in AE 16.0 (CC2019)
// You can set this in File -> Project Settings: https://drop.aescripts.com/NQurXWmG
// If you replace all "let" to "var" this expression will should work in previous versions

maskToUse = thisComp.layer("MASK").mask("Mask 1").maskPath.points();

function inside(point, path) {
    let x = point[0],
        y = point[1];
    let inside = false;
    for (let i = 0, j = path.length - 1; i < path.length; j = i++) {
        let xi = path[i][0],
            yi = path[i][1];
        let xj = path[j][0],
            yj = path[j][1];
        let intersect = ((yi > y) != (yj > y)) && (x < (xj - xi) * (y - yi) / (yj - yi) + xi);
        if (intersect) inside = !inside;
    }
    return inside;
};

r = inside(position, maskToUse);

if (r == true) {
    thisProperty.key(2).value
} else {
    thisProperty.key(1).value
};

 

 

Submit

If you would like to submit a piece for inclusion in our INSPIRATION category please submit it to us here or tag #aescripts on Instagram.