Skip to content

Instantly share code, notes, and snippets.

@jack-nie
Created April 26, 2018 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jack-nie/058c2fc0f6f5ab5b48d2972439d96fb0 to your computer and use it in GitHub Desktop.
Save jack-nie/058c2fc0f6f5ab5b48d2972439d96fb0 to your computer and use it in GitHub Desktop.
function colorText(str,phase)
{
if (phase == undefined) phase = 0;
center = 128;
width = 127;
frequency = Math.PI*2/str.length;
for (var i = 0; i < str.length; ++i)
{
red = Math.sin(frequency*i+2+phase) * width + center;
green = Math.sin(frequency*i+0+phase) * width + center;
blue = Math.sin(frequency*i+4+phase) * width + center;
document.write( '<font style="color:' + RGB2Color(red,green,blue) + '">' + str.substr(i,1) + '</font>');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment