Archive for the 'Experiments' Category

Text Scrambler

[Update: Updated the core class with functiosn to scramble text, get random characters from specific paramaters, also updated the example to show both Scramble and Unscramble in action, may post a live example]

Came accross this AS1 Tutorial, and decided to code my own class from scratch, came along nicely.

Scrambler.as: Download

Code:

package com.arcticcode.greenFlames.Text
{
	public class Scrambler
	{
		public static const ALPHABET:String = "abcdefghijklmnolpqrstuvwxyz";
		public static const NUMBERS:String = "0123456789";
		public static const SYMBOLS:String = "`¬!\"£$%^&*()_+=-[];'#./,{}~@:?><\|";
 
		public static function scramble(input:String):String
		{
			var str:String = "";
			for(var i:uint = 0;i<input.length;i++)
			{
				str += getRanChar(input.charAt(i));
			}
			return str;
		}
 
		public static function getRanChar(char:String):String
		{
			var ch:String = "";
			if(ALPHABET.indexOf(char) != -1)
			{
				ch = ALPHABET.charAt(Math.floor(Math.random()*ALPHABET.length));
				if(ch == char)
				{
					ch = getRanChar(char);
				}
			}
			else if(ALPHABET.indexOf(char.toLowerCase()) != -1)
			{
				ch = ALPHABET.charAt(Math.floor(Math.random()*ALPHABET.length)).toUpperCase();
				if(ch == char)
				{
					ch = getRanChar(char);
				}
			}
			else if(NUMBERS.indexOf(char) != -1)
			{
				ch = NUMBERS.charAt(Math.floor(Math.random()*NUMBERS.length));
				if(ch == char)
				{
					ch = getRanChar(char);
				}
			}
			else if(SYMBOLS.indexOf(char) != -1)
			{
				ch = SYMBOLS.charAt(Math.floor(Math.random()*SYMBOLS.length));
				if(ch == char)
				{
					ch = getRanChar(char);
				}
			}
			else if(char == " ")
			{
				ch = " ";
			}
			return ch;
		}
 
		public static function unscramble(input:String,target:String,letters:Boolean,numbers:Boolean,symbols:Boolean,mixedCase:Boolean,...extraChars):String
		{
			var chars:String = "";
 
			if(letters){chars += ALPHABET};
			if(mixedCase){chars += ALPHABET.toUpperCase();}
			if(numbers){chars += NUMBERS;}
			if(symbols){chars += SYMBOLS;}
			if(extraChars != null){chars += extraChars;}
 
			var str:String = input;
			var ts:String = "";
			var char:String = "";
 
			for(var i:uint=0;i<str.length;i++)
			{
				NUMBERS.indexOf(target.charAt(i)) != -1 ? char = NUMBERS.charAt(Math.floor(Math.random()*NUMBERS.length)) : char = chars.charAt(Math.floor(Math.random()*chars.length));
				str.charAt(i) != target.charAt(i) ? ts += char : ts += str.charAt(i);
			}
			return ts;
		}
	}
}

To Use:

package
{
	import com.arcticcode.greenFlames.Text.Scrambler;
	import com.arcticcode.greenFlames.utils.StringUtils;
 
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	[SWF(width=600,height=400,backgroundColor=0xFFFFFF)]
	public class TextScramble extends Sprite
	{
		private var tf:TextField;
		private var targetString:String="My Text 2008";
		private var count:uint = targetString.length; 
		private var currString:String;
		private var arr:Array;
		private var char:String = "";
 
		public function TextScramble()
		{
			init();
		}
		private function init():void
		{
			tf = new TextField();
			tf.autoSize = TextFieldAutoSize.LEFT;
			tf.defaultTextFormat = new TextFormat("Verdana",12,0);
			addChild(tf);
			tf.selectable = false;
			tf.text = "            ";
 
			addEventListener(Event.ENTER_FRAME, loop);
		}
		private function loop(e:Event):void
		{
			tf.text = Scrambler.unscramble(tf.text, targetString, true, true, false, true, " ");
			tf.text == targetString ? removeEventListener(Event.ENTER_FRAME, loop) : null;
		}
	}
}
Vote in HexoSearch Vote for this on HexoSearch!

Isometric…

I really need to stop playing with isometrics, more addictive than lego. Anyway made this from boredom.

Can you guess what it is? Post a comment if you know…

Vote in HexoSearch Vote for this on HexoSearch!

More Isometrics

Playing around with isometrics, perlin noise and sine waves. Something I have wanted to do for a while.

Anyway first app uses perlin noise for height or y pos depending if floating or not, click to toggle floating and randomise the x and y offset’s for the perlin noise.

The second app is using a simple sine wave accross a grid, well the first isometric block is using a sine, the rest just of the blocks just set their height or y pos to the one before it, again click to toggle floating.

Vote in HexoSearch Vote for this on HexoSearch!

Cantor Cheese Cross Sections…Yes Cheese!

Yet some more of the book, not long after i posted the flutterby experiments.

Renders very quick but kinda expected it to as it is very simple, 3D maybe…?

Click to generate a new set of coloured cross sections…

Vote in HexoSearch Vote for this on HexoSearch!