Skip to content

Instantly share code, notes, and snippets.

View GoodBoyNinja's full-sized avatar
🧠
You are a brain. Be a kind brain!

Good Boy Ninja GoodBoyNinja

🧠
You are a brain. Be a kind brain!
View GitHub Profile
@GoodBoyNinja
GoodBoyNinja / AfterEffectsRoundCornersRect.js
Last active November 17, 2023 22:29
Apply this expression to a path property to create a rectangle with inverted rounded corners (corners round inwards). At the beginning of the expression, you can set the corner radius and the two main points that form the rectangle (top left & bottom right). by default, those values are set to 'undefined' which will automatically create a rectan…
// USER SETTINGS
cornerRadius = undefined; // leave undefined to use comp size average;
topLeftCorner = undefined; // leave undefined to use comp zero point [0,0];
btmRightCorner = undefined; // leave undefined to use comp size point [compWidth,compHeight];
// EXPRESSION
function FindCirclePnt(cornerPnt, cornerRadius, angleFromCornerToCircle) {
circlePntX = cornerRadius * Math.cos(degreesToRadians(angleFromCornerToCircle));
circlePntY = cornerRadius * Math.sin(degreesToRadians(angleFromCornerToCircle));
@GoodBoyNinja
GoodBoyNinja / Determine Acceleration and Deceleration - After Effects Expression.jsx
Created February 1, 2021 13:22
When applied to a text layer source text, it will show "+ / - " according to whether the point the expression is looking at is speeding up or slowing down.
function AccelDeccel(point) {
xResult = "";
yResult = "";
pointVelocity = point.velocity;
pointVelocityLastFrame = point.velocityAtTime(time - thisComp.frameDuration);
xVelocityNow = Math.abs(pointVelocity[0]);
yVelocityNow = Math.abs(pointVelocity[1]);
xVelocityLastFrame = Math.abs(pointVelocityLastFrame[0]);
yVelocityLastFrame = Math.abs(pointVelocityLastFrame[1]);
@GoodBoyNinja
GoodBoyNinja / Move along the edges of the comp - After Effects Expression.jsx
Created February 1, 2021 13:25
When applied to a position property, it places it on the edges of the comp. Use "time" as the percentage input like in the example below to drive the animation.
function MoveAlongEdgesOfComp(percent, marginpercent) {
percent = (percent === undefined) ? 0 : percent % 100;
marginpercent = (marginpercent === undefined) ? 0 : clamp(marginpercent, 0, 100);
// convert the original percent value to both horizontal and vertical percent values to drive the motion
horizontalpercent = (percent >= 25 && percent <= 50) ? 100 : (percent >= 75 && percent <= 100) ? 0 : (percent < 25) ? (percent * 4) : (100 - (4 * (percent % 25)));
verticalpercent = (percent >= 0 && percent <= 25) ? 0 : (percent >= 50 && percent <= 75) ? 100 : (percent < 50) ? (percent - 25) * 4 : (100 - (4 * (percent % 25)));
midPoint = [thisComp.width * 0.5, thisComp.height * 0.5]; // use the linear function to drive each dimension
xLoc = linear(horizontalpercent, 0, 100, 0, thisComp.width);
@GoodBoyNinja
GoodBoyNinja / Move in a circle - After Effects Expression.jsx
Created February 1, 2021 13:27
This function takes simple circle properties like the radius and degrees, and returns a point on a circle, around the original value. Using this as a position expressions, then calling the function like in the example below, will result in a circular motion that's easily customizable.
function CircularMotion (theRadius, degrees, angleShift){
degrees = (degrees === undefined) ? - 90 : -degrees + 90
angleShift = (angleShift === undefined) ? 0 : -angleShift;
theRadius = (theRadius === undefined) ? 100 : theRadius;
xDir = Math.sin(degreesToRadians(degrees + angleShift));
yDir = Math.cos(degreesToRadians(degrees + angleShift));
return [xDir * theRadius, yDir * theRadius] + value;
}
@GoodBoyNinja
GoodBoyNinja / Move in a square - After Effects Expression.jsx
Created February 1, 2021 13:28
Take the original position value and returns a point on a square around it. use "time" to drive the animation like in the example below.
function SquareMotion(squareSize, percent) {
squareSize = (squareSize === undefined) ? 100 : squareSize;
percent = (percent === undefined) ? 0 : percent % 100;
sideSize = squareSize / Math.SQRT2;
halfSize = sideSize * 0.5;
perimeter = sideSize * 4; // convert the original percent value to both horizontal and vertical percent values to drive the motion
horizontalpercent = (percent >= 25 && percent <= 50) ? 100 : (percent >= 75 && percent <= 100) ? 0 : (percent < 25) ? (percent * 4) : (100 - (4 * (percent % 25)));
verticalpercent = (percent >= 0 && percent <= 25) ? 0 : (percent >= 50 && percent <= 75) ? 100 : (percent < 50) ? (percent - 25) * 4 : (100 - (4 * (percent % 25))); // use the linear function to drive each dimension
xLoc = linear(horizontalpercent, 0, 100, -halfSize, halfSize);
@GoodBoyNinja
GoodBoyNinja / Reset path location and ignore transforms - After Effects Expression.jsx
Created February 1, 2021 13:30
When applied to a path property, it recreates the existing path on the top left side of the screen and keeps it there no matter your layer transforms.
srcPath = thisProperty;
newPnts = [];
newITs = [];
newOTs = [];
for (i = 0; i < srcPath.points().length; i++) {
thisPoint = srcPath.points()[i];
thisIT = srcPath.inTangents()[i];
thisOT = srcPath.outTangents()[i];
newPnts.push(thisLayer.fromComp(thisPoint));
@GoodBoyNinja
GoodBoyNinja / Check Current OS (Win or MacOS).jsx
Created February 1, 2021 13:38
This function is described as "isMacOS" in order to easily use the returned result (true / false) to do stuff accordingly. Check out the example code for a proper use of this function.
function isMacOS(){
var currentSystemOS = String($.os).toLowerCase();
if (currentSystemOS.indexOf("mac") == -1) {
return false
} else {
return true;
}
}
isMacOS();
@GoodBoyNinja
GoodBoyNinja / Dockable ScriptUI Panel.jsx
Created February 1, 2021 13:42
Copy and paste this template and write any code related to your UI inside the "buildUI" function. You can use 'ScriptUI Dialog Builder' - https://scriptui.joonas.me/ and then export the code and paste it inside the "buildUI" function. Note: Your script becomes dockable only when you place it in the "scriptUI Panels" folder. Reboot After-Effects …
(function(thisObj) {
// Any code you write here will execute before the panel is built.
buildUI(thisObj); // Calling the function to build the panel
function buildUI(thisObj) {
@GoodBoyNinja
GoodBoyNinja / Get the layer of the selected property - After Effects Script .jsx
Created February 1, 2021 13:45
It takes one property argument, and returns the layer of which this property belongs to.
function LayerParentOfProperty(property) {
try {
return property.propertyGroup(property.propertyDepth);
} catch (e) {
return property;
}
}
// example of use, gets the first selected property.
var selectedProperty = app.project.activeItem.selectedProperties[0];
function AllEffectsOnLayer(layer) {
if (layer !== undefined) {
// alert ("shit")
var effectsGroup = layer("ADBE Effect Parade");
//var effectsOnLayer = new Array();