Page 1 of 1

Flowing letters!

Posted: Mon Apr 23, 2012 8:47 pm
by Chris
I was bored and wanted to try it out for some time now.

Code: Select all

<!DOCTYPE html>
<html>
	<head>
		<title>LOL</title>
		<style type="text/css">
		*{font-family:monospace;}
		</style>
	</head>
	<body>
		<script type="text/javascript">
		var alphabet = '•????????$??-=~`!@#$%^&*()?|{}[]:;<>,./\'"_+0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz';

		var FlowLetter = function(letter)
		{
			this.element = document.createElement('span');
			this.letter = letter[0]; // make sure there is only one letter
			this.loops = 0;
			this.change = function()
			{
				var _this = this;
				this.loop = setTimeout(function(){_this.change()}, Math.floor( (Math.random()+1) *5))
				this.loops++;
				this.element.innerHTML = alphabet[this.loops];

				if( this.letter == alphabet[this.loops] )
				{
					this.element.innerHTML = this.letter;
					clearTimeout(this.loop)
				}
			}
			this.change()
		}
		var FlowString = function(string)
		{
			this.string = string;
			this.element = document.createElement('p');
			this.loop = null;
			this.loops = 0;
			this.addLetter = function()
			{
				var _this = this;
				this.loop = setTimeout(function(){_this.addLetter()}, Math.floor( (Math.random()+1) *5));
				if( this.loops == this.string.length )
				{
					clearTimeout(this.loop);
					return;
				}
				var letter = new FlowLetter(this.string[this.loops]);
				this.element.appendChild(letter.element);
				this.loops++;
			}
			this.addLetter();
		}

		var heading = new FlowString('Type some shit in and see the magic! ');
		document.body.appendChild(heading.element)


		typedLetters = [];
		window.onkeydown = function(e)
		{
			e.preventDefault();
			switch(e.keyCode)
			{
				case 16: return;
				case 8:
					document.body.removeChild(typedLetters[(typedLetters.length-1)].element);
					typedLetters.pop(typedLetters[(typedLetters.length-1)])
				return;
			}

			var letter = new FlowLetter(String.fromCharCode(e.keyCode).toLowerCase());
			typedLetters.push(letter);
			document.body.appendChild(letter.element)
		}
		</script>
	</body>
</html>

Re: Flowing letters!

Posted: Mon Apr 23, 2012 11:38 pm
by Jackolantern
Haha! Very cool and stylized! Only thing is that the European encoding on the page that allows those leading shape characters is causing problems in American IDEs. First I just tried textpad for a fast copy/paste, but it rejected it due to the characters. I then tried a couple of IDEs to change the encoding, and they kept saying they would have to turn the shapes into ?s, and they weren't cooperative to try to change the encoding to anything besides ASCII for fear that browsers would not read it. So I got a couple of undefineds popping up and a whole lot of '?', but the effect was still very cool!

Re: Flowing letters!

Posted: Tue Apr 24, 2012 1:58 am
by Ark
wow very cool!

Re: Flowing letters!

Posted: Thu Aug 02, 2012 5:58 am
by xgatherer
Awesome dude!
Btw when i pressed '-' 'undefined' appears instead of '-'.
Nice share