Variation on a theme: String wipe effect where each character appears as a random ascii char.
/*
Inserts random character at specified position in string,
and sets subsequent characters to blank.
toneburst 2008
http://machinesdontcare.wordpress.com
*/
function (__string outputString, __structure outputStruct) main (__string inputString, __number Position)
{
// Initialise vars
var result = new Object();
var outString = "";
var outArray = new Array();
if(!_testMode) {
// Set character count to length of string
var chars = inputString.length;
// Set threshold start position for character randomisation
var wipePos = Math.floor(Position * chars);
// Loop through characters
for (i = 0; i < chars; i++) {
// Generate random number in 65 > 122 range
var rand = Math.random() * 57 + 65;
// Accumulate outString by picking from inputString, space character or random ASCII character
var char;
if (i < wipePos) {
// Current char is less than threshold wipe position
char = inputString.charAt(i);
} else if (i > wipePos) {
// Current char is more than threshold wipe position
char = " ";
} else {
// Current char is at threshold wipe position in input string
// so character will be randomised
char = String.fromCharCode(rand);
}
outString += char;
// Set output array at index i
outArray[i] = char;
}
}
// Set output string + struct
result.outputString = outString;
result.outputStruct = outArray;
// Output
return result;
}
Updated version of the QTZ uploaded to the Box widget.
‘tb JS-ASCII Demos 1.0.4′
0 Responses to “Minor JS String Variation”