Flowing letters!

Place to place any code snippets, completed games, or even uncompleted games for IR users to use.
Post Reply
User avatar
Chris
Posts: 1580
Joined: Wed Sep 30, 2009 7:22 pm

Flowing letters!

Post 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>
Fighting for peace is declaring war on war. If you want peace be peaceful.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Flowing letters!

Post 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!
The indelible lord of tl;dr
User avatar
Ark
Posts: 427
Joined: Wed Jun 01, 2011 10:25 pm

Re: Flowing letters!

Post by Ark »

wow very cool!
Orgullo Catracho
xgatherer
Posts: 8
Joined: Wed Jul 25, 2012 1:51 am

Re: Flowing letters!

Post by xgatherer »

Awesome dude!
Btw when i pressed '-' 'undefined' appears instead of '-'.
Nice share
Post Reply

Return to “Code Sharing”