Created
August 5, 2023 15:23
-
-
Save cyrillsemenov/d09487080c38bb856594295e1412c543 to your computer and use it in GitHub Desktop.
Generate pie chart in After effects using createPath() expression
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const r = effect("Radius")("Slider"); | |
const progress = Math.max(Math.min(effect("Completion")("Slider"), 1), 0); | |
const ratio = 0.551915024494; | |
const t = r*ratio; | |
const points = [[r,0],[0,r],[-r,0],[0,-r],[r,0]]; | |
const inTangents = [[0,t],[-t,0],[0,-t],[t,0],[0,0]]; | |
const outTangents = [[0,0],[t,0],[0,t],[-t,0],[0,-t]]; | |
const endAngle = progress * 2 * Math.PI; | |
const endVertex = [Math.cos(endAngle), Math.sin(endAngle)] * r; | |
const endOutTangent = normalize([endVertex[1], -endVertex[0]])*t*((progress*4) % 1); | |
let r_points = [[0,0], endVertex], | |
r_inTangents = [[0,0],[0,0]], | |
r_outTangents = [[0,0],endOutTangent]; | |
const limit = Math.floor(progress * 4); | |
for (i = 0; i <= limit; i++) { | |
r_points.unshift(points[i]); | |
r_inTangents.unshift(inTangents[i]); | |
r_outTangents.unshift(outTangents[i]); | |
} | |
createPath(r_points, r_inTangents, r_outTangents) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment