In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

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

LIFE GAME

touch screen.
/**
 * 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/xnit
 */

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;
	
	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/wAAAKgAAEAAAgAAdAYAgAIA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QP8AAACoAABAAAIAAHQGAIACAAAA0AAAAAYCAADIBgBABAAAAHQKAgAGAAAABAYCAAYDAADYAAAAAAAAAHQMAgAMAgAAdAwBAAwDAAB0EAMEAABAAAQQAwQMAEAAwBQDxBAAQAB0CAPMFABsAHQAAEAIAAAABAAAQAgBAAB0DAIAAAMAAAQMAgAIAgAAdAAAgAwAAADIAABA/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 lastX:Number = mouseX;
			var lastY:Number = mouseY;
			var drawing:Boolean = false;
			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)
				{
					drawShape.graphics.clear();
					drawShape.graphics.lineStyle(1, 0xFFFFFF);
					drawShape.graphics.moveTo(lastX, lastY);
					drawShape.graphics.lineTo(mouseX, mouseY);
					canvas.draw(drawShape);
				}
				canvas.unlock();
				lastX = mouseX;
				lastY = mouseY;
			});
		}
		
	}
	
}