Dead Code Preservation :: Archived AS3 works from wonderfl.net

symmetry LIFE GAME

Get Adobe Flash player
by cpu_t 29 Jan 2013
/**
 * Copyright cpu_t ( http://wonderfl.net/user/cpu_t )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/g7b2
 */

// forked from cpu_t's LIFE GAME
package 
{
	import mx.utils.Base64Decoder;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Shader;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filters.ShaderFilter;
        import flash.geom.Matrix;
	
	public class Main extends Sprite 
	{
		
		public function Main():void 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private var LIFEGAME_PBJ:String = "pQEAAACkCABsaWZlZ2FtZaAMbmFtZXNwYWNlAGNvbS5jcHV0YWxsAKAMdmVuZG9yAGNwdXQAoAh2ZXJzaW9uAAEAoQECAAAMX091dENvb3JkAKMABHNyYwChAgQBAA9kc3QAMgGAgAAAAAAyAYBAAAAAADIAACAAAAAAMgIAgAAAAAAyAgBAAAAAADICACAAAAAAMgIAEAAAAAAyAwCAP4AAADIDAEA/gAAAHQMAMQMAEAAyAAAQAAAAAAIAABADAIAAHQMAgAAAwAAyAAAQAAAAAAIAABADAMAAHQMAQAAAwAAdBADBAAAQAAEEAMEDABAAMAUA8QQAEAAdAgDzBQAbAB0AABACAAAAAQAAEAIAQAAdAwCAAADAAAEDAIACAIAAHQAAIAMAAAAyAAAQP8AAACoAABAAAIAAHQGAIACAAAA0AAAAAYCAADIBgBABAAAAHQKAgAGAAAABAYCAAYDAADYAAAAAAAAAMgAAEAAAAAACAAAQAwCAAB0DAIAAAMAAMgAAEAAAAAAdAwBAAADAAB0EAMEAABAAAQQAwQMAEAAwBQDxBAAQAB0CAPMFABsAHQAAEAIAAAABAAAQAgBAAB0DAIAAAMAAAQMAgAIAgAAdAAAgAwAAADIAABA/wAAAK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IAAHQAAIAMAAAAyAAAQP8AAACoAABAAAIAAHQGAIACAAAA0AAAAAYCAADIBgBABAAAAHQKAgAGAAAABAYCAAYDAADYAAAAAAAAAHQMAgAMAgAAdAwBAAwDAAB0EAMEAABAAAQQAwQMAEAAwBQDxBAAQAB0CAPMFABsAHQAAEAIAAAABAAAQAgBAAB0DAIAAAMAAAQMAgAIAgAAdAAAgAwAAADIAABA/wAAAKgAAEAAAgAAdAYAgAIAAADQAAAABgIAAMgGAEAEAAAAdAoCAAYAAAAEBgIABgMAANgAAAAAAAAAwBADxAAAQAB0CAPMEABsAHQAAEAIAAAABAAAQAgBAAB0DAIAAAMAAAQMAgAIAgAAdAAAgAwAAADIAABA/wAAAKgAAEAAAgAAdAYAgAIAAADQAAAABgIAAMgGAQAEAAAA2AAAAAAAAADIBgCABAAAAKAGAQAGAgAAdAYAQAIAAADQAAAABgMAAMgGAIAIAAAArAYAgAYAAAB0CgIAAgAAAMgGAIAMAAAArAYCAAYCAAB0CgEAAgAAAHQGAIAKAAAAtAYAgAoBAADQAAAABgIAAMgEAgD+AAAAyAQBAP4AAADIBACA/gAAAMgEAED+AAAA1AAAAAAAAADIBAIA/gAAAMgEAQAAAAAAyAQAgAAAAADIBABAAAAAANgAAAAAAAAA1AAAAAAAAADIBgCADAAAAKwGAIAGAAAAdAoCAAIAAADIBgCADAAAAKwGAgAGAgAAdAoBAAIAAAB0BgCACgAAALQGAIAKAQAA0AAAAAYCAADIBAIA/gAAAMgEAQD+AAAAyAQAgP4AAADIBABA/gAAANQAAAAAAAAAyAQCAP4AAADIBAEAAAAAAMgEAIAAAAAAyAQAQAAAAADYAAAAAAAAANgAAAAAAAAA=";
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			// entry point
			
			graphics.beginFill(0);
			graphics.drawRect(0, 0, 465, 465);
			
                        var decorder:Base64Decoder = new Base64Decoder();
                        decorder.decode(LIFEGAME_PBJ);
			var shader:Shader = new Shader(decorder.toByteArray());
			var shaderFilter:ShaderFilter = new ShaderFilter(shader);
			
			var canvas:BitmapData = new BitmapData(465, 465, true, 0);
			var bitmap:Bitmap = new Bitmap(canvas);
			addChild(bitmap);
			
			var drawShape:Shape = new Shape();
                        var drawData:BitmapData = new BitmapData(465, 465, true, 0);
			var lastX:Number = mouseX;
			var lastY:Number = mouseY;
			var drawing:Boolean = false;
                        var reflectMatrix:Matrix = new Matrix();
                        reflectMatrix.scale(-1 ,1);
                        reflectMatrix.translate(465, 0);
			stage.addEventListener(MouseEvent.MOUSE_DOWN, function(e:*):void
			{
				drawing = true;
			});
			stage.addEventListener(MouseEvent.MOUSE_UP, function(e:*):void
			{
				drawing = false;
			});
			stage.addEventListener(Event.ENTER_FRAME, function(e:*):void
			{
				canvas.lock();
				canvas.applyFilter(canvas, canvas.rect, canvas.rect.topLeft, shaderFilter);
				if (drawing)
				{
                                        drawData.lock();
                                        drawData.fillRect(drawData.rect, 0x00000000);
					drawShape.graphics.clear();
					drawShape.graphics.lineStyle(1, 0xFFFFFF);
					drawShape.graphics.moveTo(int(lastX), int(lastY));
					drawShape.graphics.lineTo((mouseX), int(mouseY));
					drawData.draw(drawShape);
                                        drawData.unlock();
                                        canvas.draw(drawData);
					canvas.draw(drawData, reflectMatrix);
				}
				canvas.unlock();
				lastX = mouseX;
				lastY = mouseY;
			});
		}
		
	}
	
}