-
Random but predefined increments for counter
Hello,
I am trying to have my counter grow only by predefined increments (1, 5, 10, 25).
I have linked it to my control slider and placed keyframes to which values it should go, but it is getting there 1 by 1.here is the expression I am currently using and trying to modify further:
// Pick-whip number from Slider or Point Control and assign to mySlider
// For example: var mySlider = effect(“Point Control”)(“Point”)[0];
var mySlider = thisComp.layer(“CONTROL mn”).effect(“COUNTER”)(“Slider”)*10;
// Use the commas function defined below to format your number.
// Commas takes three properties – the number input,
// the size of the groups of numbers and the number of decimal places.
// You can use this function and only give it the base number.
var numberstring = commas(mySlider);
// This is the final output of this expression.
// Use quotes around other text that you want to join with your numberstring variable.
// eg. ‘$’ + numberstring + ‘ RAISED’
‘ ‘ + numberstring;
function commas(number, groupSize, decimals){
// Default settings if only a number is provided.
groupSize = (groupSize == undefined) ? 3 : groupSize;
decimals = (decimals == undefined) ? 0 : decimals;
var theComma = ” “;
// Round to given decimal places and convert number to string
var strNumber = Number(number).toFixed(decimals).toString()
// Store decimal places separately, with a bullet point if they exist or empty string if not.
var arrNumber = strNumber.split(‘.’)
var decimalPlaces = (arrNumber.length > 1) ? ‘.’ + arrNumber[1] : ”;
// Convert to array to split into characters
var anum = arrNumber[0].split(”);
// New array to hold formatted number
var fnum = new Array();
var count = 0;
// Process the characters in reverse, inserting a comma after each groupSize.
for(var i = anum.length-1; i >= 0; i–){
fnum.push(anum[i]);
count++;
// If the count is divisble by the groupSize and this is not the last (ie. first) character, add a comma.
if(count % groupSize == 0 && i != 0){
fnum.push(theComma);
}
}
return fnum.reverse().join(”) + decimalPlaces;
}
Thank you so much for any help ♥