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

forked from: Dots

Get Adobe Flash player
by HGWLAB 18 Dec 2008
// forked from seagirl's Dots
// write as3 code here..
package {
	
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Matrix;
	import flash.geom.Point;
	import flash.text.TextField;

	[SWF(backgroundColor="#FFFFFF")]
	
	public class Dots extends Sprite
	{
		public function Dots()
		{
			init();
		}
		
		private var bmp1:Bitmap;
		private var bmp2:Bitmap;
		
		private var point:Point = new Point(0, 0);
		
		private function init():void
		{
			stage.frameRate = 30;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			

			bmp1 = new DotsBitmap(stage.stageWidth, stage.stageHeight, DotsPattern.DOT_CIRCLE, 0xFFFF0000);
			addChild(bmp1);
			
			bmp2 = new DotsBitmap(stage.stageWidth, stage.stageHeight, DotsPattern.DIYA, 0xff00FF00);
			addChild(bmp2);
			
			var t:TextField
			
			
			stage.addEventListener( Event.ENTER_FRAME, update);

		}
		
		
		private var currentscale:Number = 1;
		private var p:Boolean = true;
		private function update(e:Event=null):void
		{
			currentscale = (p)? currentscale+.001 : currentscale-.001;

			
			var m:Matrix = new Matrix();
			m.translate(-bmp1.width*.5,-bmp1.height*.5);
			m.scale(currentscale,currentscale);
			m.translate(bmp1.width*.5,bmp1.height*.5);
			bmp1.transform.matrix = m;
			
			
			if(currentscale<1) p = true;
			if(currentscale>1.2) p = false;
			
		}
		
	}
}


	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.geom.Matrix;

	class DotsBitmap extends Bitmap
	{
		private var color:uint = 0xFFFFFF;
		private var basecolor:uint = 0x0;
		private var maximumW:Number = 100;
		private var maximumH:Number = 100;
		private var _pattern:Array;
		private var _useTransparent:Boolean = true;
		
		public function DotsBitmap(	
											width:Number,
											height:Number,
											patternMatrix:Array,
											patternColor:uint,
											fillColor:uint			= 0x0,
											transparent:Boolean		= true,
											pixelSnapping:String	= 'never', 
											smoothing:Boolean		= false
										)
		{
			super(null, pixelSnapping, smoothing);
			color = patternColor;
			basecolor = fillColor;
			_pattern = patternMatrix;
			_useTransparent = transparent;
			setSize( width, height);
		}
		
		
		
		/**
		 * setting bitmap size
		 * @param width
		 * @param height
		 * 
		 */		
		public function setSize(width__:Number, height__:Number):void
		{
			if(bitmapData!=null)
			{
				bitmapData.dispose();
				bitmapData = null;
			}
			
			maximumW = width__;
			maximumH = height__;
			update();
		}
		
		
		
		/**
		 * get pattern of dotted as array
		 * @param ptn__
		 * 
		 */
		public function set pattern(ptn__:Array):void
		{
			_pattern = ptn__;
			update();
		}
		
		
		
		public function get pattern ():Array
		{
			return _pattern;
		}
		
		
		
		
		
		private function update():void
		{
			var ptnSrc:BitmapData = makePattern();
			var srcW:int = ptnSrc.width;
			var srcH:int = ptnSrc.height;			
			var repX:int = Math.ceil( maximumW/srcW );
			var repY:int = Math.ceil( maximumH/srcH );
			
			
			bitmapData = new BitmapData(maximumW, maximumH, _useTransparent, basecolor);
			bitmapData.draw( ptnSrc );
 			for(var ix:int=0; ix<repX; ix++)
			{
				for(var iy:int=0; iy<repY; iy++)
				{
					bitmapData.draw( ptnSrc, new Matrix(1,0,0,1, ix*srcW, iy*srcH) );
				}
			}
			ptnSrc.dispose();
			ptnSrc = null;
			
 		}



		private function makePattern():BitmapData
		{
			var tmpW:int = _pattern.length;
			var tmpH:int =_pattern[0].length ;
			var times:int = 10;
			
			var tmp:BitmapData = new BitmapData(tmpW, tmpH, _useTransparent, basecolor);
			var result:BitmapData = new BitmapData(tmpW*times, tmpH*times, _useTransparent, basecolor);
			
			var ix:int;
			var iy:int;
			
 			tmp.lock()
			for(ix=0; ix<tmpW; ix++)
			{
				var current:Array = _pattern[ix];
				for(iy=0; iy<tmpH; iy++)
				{
					if(current[iy]==1)
					{
						if(_useTransparent)
							tmp.setPixel32(ix, iy, color);
						else	
							tmp.setPixel(ix, iy, color);
					}
				}
			}
			tmp.unlock();
			
			result.lock()
			for(ix=0; ix<result.width; ix+=tmpW)
			{
				for(iy=0; iy<result.height; iy+=tmpH)
				{
					result.draw(tmp, new Matrix(1,0,0,1,ix,iy));
				}
			}
			result.unlock();

			tmp.dispose();
			tmp = null;
			return result;
		}

		
	}









	class DotsPattern
	{
		public static const NOMAL:Array =	[	
												[1,0],
												[0,0]
											];
		
		
		
		public static const CLOSS:Array = [	
												[1,0],
												[0,1]
											];
											
											
												
		
		public static const DIAGONAL_WIDE:Array = [
												[0,0,0,0,1,1,1,1],
												[0,0,0,1,1,1,1,0],
												[0,0,1,1,1,1,0,0],
												[0,1,1,1,1,0,0,0],
												[1,1,1,1,0,0,0,0],
												[1,1,1,0,0,0,0,1],
												[1,1,0,0,0,0,1,1],
												[1,0,0,0,0,1,1,1]
											];
											
		
											
		
												
		public static const DIYA:Array = [	
													[0,0,0,1,0,0],
													[0,0,1,0,1,0],
													[0,1,0,0,0,1],
													[0,0,1,0,1,0],
													[0,0,0,1,0,0],
													[0,0,0,0,0,0]
												];
												
												
												
		public static const DOT_CIRCLE:Array = [	
													[0,0,0,1,0,1,0,1,0,0,0,	0,0,0,0,0,0,0,0,0,0,0],
													[0,0,1,0,1,0,1,0,1,0,0,	0,0,0,0,0,0,0,0,0,0,0],
													[0,1,0,1,0,1,0,1,0,1,0,	0,0,0,0,0,0,0,0,0,0,0],
													[1,0,1,0,1,0,1,0,1,0,1,	0,0,0,0,0,0,0,0,0,0,0],
													[0,1,0,1,0,1,0,1,0,1,0,	0,0,0,0,0,0,0,0,0,0,0],
													[1,0,1,0,1,0,1,0,1,0,1,	0,0,0,0,0,0,0,0,0,0,0],
													[0,1,0,1,0,1,0,1,0,1,0,	0,0,0,0,0,0,0,0,0,0,0],
													[1,0,1,0,1,0,1,0,1,0,1,	0,0,0,0,0,0,0,0,0,0,0],
													[0,1,0,1,0,1,0,1,0,1,0,	0,0,0,0,0,0,0,0,0,0,0],
													[0,0,1,0,1,0,1,0,1,0,0,	0,0,0,0,0,0,0,0,0,0,0],
													[0,0,0,1,0,1,0,1,0,0,0,	0,0,0,0,0,0,0,0,0,0,0],
													
													[0,0,0,0,0,0,0,0,0,0,0,	0,0,0,1,0,1,0,1,0,0,0],
													[0,0,0,0,0,0,0,0,0,0,0,	0,0,1,0,1,0,1,0,1,0,0],
													[0,0,0,0,0,0,0,0,0,0,0,	0,1,0,1,0,1,0,1,0,1,0],
													[0,0,0,0,0,0,0,0,0,0,0,	1,0,1,0,1,0,1,0,1,0,1],
													[0,0,0,0,0,0,0,0,0,0,0,	0,1,0,1,0,1,0,1,0,1,0],
													[0,0,0,0,0,0,0,0,0,0,0,	1,0,1,0,1,0,1,0,1,0,1],
													[0,0,0,0,0,0,0,0,0,0,0,	0,1,0,1,0,1,0,1,0,1,0],
													[0,0,0,0,0,0,0,0,0,0,0,	1,0,1,0,1,0,1,0,1,0,1],
													[0,0,0,0,0,0,0,0,0,0,0,	0,1,0,1,0,1,0,1,0,1,0],
													[0,0,0,0,0,0,0,0,0,0,0,	0,0,1,0,1,0,1,0,1,0,0],
													[0,0,0,0,0,0,0,0,0,0,0,	0,0,0,1,0,1,0,1,0,0,0]
												];
												
												
	}