Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gordielachance/122dbac205c4c422a2590d7a6177b9be to your computer and use it in GitHub Desktop.
Save gordielachance/122dbac205c4c422a2590d7a6177b9be to your computer and use it in GitHub Desktop.
After Effects Expression : Reveal text (TypeOn + blinking cursor)
//put this expression for the 'Source Text' value on your text layer, and add 4 markers on the layer : 'cursorStart', 'textStart', 'textStop', 'cursorStop'
cursor="|";
cursorBlink = 1; //seconds
txt = value;
timeIn = thisLayer.inPoint; //seconds
txtSize = text.sourceText.length;
animateText = true;
showCursor = true;
//check if required markers exists
try{
textStart = marker.key('textStart').time;
textStop = marker.key('textStop').time;
}catch(e){
AnimateText = false;
}
//check if required markers exists
try{
cursorStart = marker.key('cursorStart').time;
cursorStop = marker.key('cursorStop').time;
}catch(e){
showCursor = false;
}
if (animateText){
duration = textStop - textStart; //type-on duration in seconds
txtIdx = linear(time, textStart, textStop, 0, txtSize);
txt = substr(0,txtIdx)
}
if (showCursor){
F = Math.round( (time + cursorStart) % cursorBlink );
if ( (time > cursorStart) && (time < cursorStop) && (F==1) ) {
txt += cursor;
}
}
txt;
@gordielachance
Copy link
Author

gordielachance commented Jan 5, 2017

...Or with a slider 'txtComplete' (0 to 100 percent) that you can use to animate the text progression :

txt = value;
timeIn = thisLayer.inPoint; //seconds
txtSize = text.sourceText.length;
cursor="|";
cursorBlink = 1; //seconds
txtComplete = 100; //percents - add a slider 'txtComplete' on your layer to animate this value

animateText = true;
showCursor = true;

//check if required markers exists
try{
  txtComplete = effect("txtComplete")("Slider");
}catch(e){
  AnimateText = false;
}

//check if required markers exists
try{
  cursorStart = marker.key('cursorStart').time;
  cursorStop = marker.key('cursorStop').time;
}catch(e){
  showCursor = false;
}


if (animateText){
  txtIdx = txtSize / 100 * txtComplete;
  txt = substr(0,txtIdx)
}

if (showCursor){
  F = Math.round( (time + cursorStart) % cursorBlink );

  if ( (time > cursorStart) && (time < cursorStop) &&  (F==1) ) {
    txt += cursor;
  }

}

txt;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment