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

点描風

コードは書き殴った感じで、きれいではないですけど。。
/**
 * Copyright moringo2 ( http://wonderfl.net/user/moringo2 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/gKnd
 */

package{
	
	//コードは書き殴った感じで、きれいではないですけど。。
	import flash.display.*;
	import flash.net.*
	import flash.events.Event;
	import flash.geom.*;
	import flash.system.LoaderContext;
	
	import caurina.transitions.Tweener;
	
	
	public class IMTest extends MovieClip{
		
		private const imgPaths:Array = ["http://moringo.moo.jp/out/b01.jpg","http://moringo.moo.jp/out/b02.jpg",
										"http://moringo.moo.jp/out/b03.jpg","http://moringo.moo.jp/out/b04.jpg",
										"http://moringo.moo.jp/out/b05.jpg"];
		
		
		private var canvas:Sprite
		private var bm:Bitmap;
		private var bmd:BitmapData;
		private var pixels:Vector.<uint>;
		private var counter:int = 0;
		private var loader:Loader;
		
		public function IMTest(){
			init();			
		}
		
		private function init(){
			counter = 0;
			canvas = new Sprite();
			addChild(canvas)
			loader = new Loader();
			loader.load(new URLRequest(imgPaths[Math.floor(Math.random()*6)]),new LoaderContext(true))
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE,comp)
		}
		
		private function comp(e:Event){
			loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,comp)
			bm = loader.content as Bitmap;
			bmd = bm.bitmapData;
			pixels = bm.bitmapData.getVector(new Rectangle(0,0,bmd.width,bmd.height));			
			canvas.addEventListener(Event.ENTER_FRAME,drawCircle)
			
		}
		
		private function drawCircle(e:Event){
			var s:Sprite = e.target as Sprite;
			for(var i:int=0; i<40; i++){
				var randX:int = Math.floor(Math.random() * bmd.width)+1;
				var randY:int = Math.floor(Math.random() * bmd.height)+1;
				
				var pixelnumber:int = bmd.width*(randY-1) +randX;
				s.graphics.beginFill(hex(avgColor(pixelnumber)),Math.random()*0.6+0.4);
				s.graphics.drawCircle(randX,randY,Math.random()*5+1);
				s.graphics.endFill();
				
			}
			counter ++;
			if(counter >= 350){
				e.target.removeEventListener(Event.ENTER_FRAME,drawCircle)
				loader = null;
				removeChild(canvas);
				canvas = null;
				bm = null;
				bmd = null;
				init();
			}else{
				
			}
		}
		
		
		private function avgColor(pix:uint):Array{
			var p:Point = positionXY(pix);
			var targetPositions:Array
			if(p.x == 1 && p.y ==1){
				targetPositions = [1,2,3, 
									1+bmd.width, 1+bmd.width+1, 1+bmd.width+2,
									1+bmd.width*2, 1+bmd.width*2+1, 1+bmd.width*2+2];
			}else if(p.x == 2 && p.y ==1){
				targetPositions = [1,2,3,4,
									1+bmd.width, 1+bmd.width+1, 1+bmd.width+2, 1+bmd.width+3,
									1+bmd.width*2, 1+bmd.width*2+1, 1+bmd.width*2+2,1+bmd.width*2+3];
				
			}else if(p.x >= 3 && p.x <= bmd.width-2 && p.y == 1){
				targetPositions = [p.x-2, p.x-1, p.x, p.x+1, p.x+2,
								   p.x+bmd.width-2, p.x+bmd.width-1, p.x+bmd.width, p.x+bmd.width+1, p.x+bmd.width+2,
								   p.x+bmd.width*2-2, p.x+bmd.width*2-1, p.x+bmd.width*2, p.x+bmd.width*2+1, p.x+bmd.width*2+2 ]
			
			}else if(p.x == bmd.width-1 && p.y ==1){
				targetPositions = [p.x-2, p.x-1, p.x, p.x+1, 
								   p.x+bmd.width-2, p.x+bmd.width-1, p.x+bmd.width, p.x+bmd.width+1, 
								   p.x+bmd.width*2-2, p.x+bmd.width*2-1, p.x+bmd.width*2, p.x+bmd.width*2+1 ]
				
			}else if(p.x == bmd.width && p.y ==1){
				targetPositions = [p.x-2, p.x-1, p.x,
								   p.x+bmd.width-2, p.x+bmd.width-1, p.x+bmd.width, 
								   p.x+bmd.width*2-2, p.x+bmd.width*2-1, p.x+bmd.width*2 ]
			}else if(p.x == 1 && p.y ==2){
				targetPositions = [pix-bmd.width, pix-bmd.width+1, pix-bmd.width+2, 
								   pix, pix+1, p.x+2,
								   pix+bmd.width, pix+bmd.width+1, pix+bmd.width+2, 
								   pix+bmd.width*2, pix+bmd.width*2+1, pix+bmd.width*2+2 ]							
			}else if(p.x == 2 && p.y ==2){
				targetPositions = [pix-bmd.width-1, pix-bmd.width, pix-bmd.width+1, pix-bmd.width+2, 
								   pix-1, pix, pix+1, pix+2,
								   pix+bmd.width-1, pix+bmd.width, pix+bmd.width+1, pix+bmd.width+2, 
								   pix+bmd.width*2-1, pix+bmd.width*2, pix+bmd.width*2+1, pix+bmd.width*2+2 ]
							
			}else if(p.x >= 3 && p.x <= bmd.width-2 && p.y ==2){
				targetPositions = [pix-bmd.width-2, pix-bmd.width-1, pix-bmd.width, pix-bmd.width+1, pix-bmd.width+2, 
								   pix-2, pix-1, pix, pix+1, pix+2,
								   pix+bmd.width-2, pix+bmd.width-1, pix+bmd.width, pix+bmd.width+1, pix+bmd.width+2, 
								   pix+bmd.width*2-2, pix+bmd.width*2-1, pix+bmd.width*2, pix+bmd.width*2+1, pix+bmd.width*2+2]
				
			}else if(p.x == bmd.width-1 && p.y ==2){
				targetPositions = [pix-bmd.width-2, pix-bmd.width-1, pix-bmd.width, pix-bmd.width+1, 
								   pix-2, pix-1, pix, pix+1, pix+2,
								   pix+bmd.width-2, pix+bmd.width-1, pix+bmd.width, pix+bmd.width+1,
								   pix+bmd.width*2-2, pix+bmd.width*2-1, pix+bmd.width*2, pix+bmd.width*2+1]
			}else if(p.x == bmd.width && p.y ==2){
				targetPositions = [pix-bmd.width-2, pix-bmd.width-1, pix-bmd.width,
								   pix-2, pix-1, pix, pix+1, pix+2,
								   pix+bmd.width-2, pix+bmd.width-1, pix+bmd.width,
								   pix+bmd.width*2-2, pix+bmd.width*2-1, pix+bmd.width*2]
			}else if(p.x == 1 && p.y >=3 && p.y<=bmd.height-2){
				targetPositions = [pix-bmd.width*2, pix-bmd.width*2+1, pix-bmd.width*2+2,
								   pix-bmd.width, pix-bmd.width+1, pix-bmd.width+2,
								   pix, pix+1, pix+2, 
								   pix+bmd.width, pix+bmd.width+1, pix+bmd.width+2,
								   pix+bmd.width*2, pix+bmd.width*2+1, pix+bmd.width*2+2]
				
			}else if(p.x == 2 && p.y >=3 && p.y<=bmd.height-2){
				targetPositions = [pix-bmd.width*2-1, pix-bmd.width*2, pix-bmd.width*2+1, pix-bmd.width*2+2,
								   pix-bmd.width-1, pix-bmd.width, pix-bmd.width+1, pix-bmd.width+2,
								   pix-1, pix, pix+1, pix+2, 
								   pix+bmd.width-1, pix+bmd.width, pix+bmd.width+1, pix+bmd.width+2,
								   pix+bmd.width*2-1, pix+bmd.width*2, pix+bmd.width*2+1, pix+bmd.width*2+2]
			}else if(p.x == bmd.width-1 && p.y >=3 && p.y<=bmd.height-2){
				targetPositions = [pix-bmd.width*2-2, pix-bmd.width*2-1, pix-bmd.width*2, pix-bmd.width*2+1,
								   pix-bmd.width-2, pix-bmd.width-1, pix-bmd.width, pix-bmd.width+1,
								   pix-2,pix-1, pix, pix+1,
								   pix+bmd.width-2,pix+bmd.width-1, pix+bmd.width, pix+bmd.width+1,
								   pix+bmd.width*2-2, pix+bmd.width*2-1, pix+bmd.width*2, pix+bmd.width*2+1]
			}else if(p.x == bmd.width && p.y >=3 && p.y<=bmd.height-2){
				targetPositions = [pix-bmd.width*2-2, pix-bmd.width*2-1, pix-bmd.width*2,
								   pix-bmd.width-2, pix-bmd.width-1, pix-bmd.width,
								   pix-2,pix-1, pix,
								   pix+bmd.width-2,pix+bmd.width-1, pix+bmd.width,
								   pix+bmd.width*2-2, pix+bmd.width*2-1, pix+bmd.width*2]
			}else if(p.x == 1 && p.y == bmd.height -1){
				targetPositions = [pix-bmd.width*2, pix-bmd.width*2+1, pix-bmd.width*2+2,
								   pix-bmd.width, pix-bmd.width+1, pix-bmd.width+2,
								   pix,pix+1, pix+2,
								   pix+bmd.width,pix+bmd.width+1, pix+bmd.width+2]
			}else if(p.x == 1 && p.y == bmd.height){
				targetPositions = [pix-bmd.width*2, pix-bmd.width*2+1, pix-bmd.width*2+2,
								   pix-bmd.width, pix-bmd.width+1, pix-bmd.width+2,
								   pix,pix+1, pix+2]
			}else if(p.x == 2 && p.y == bmd.height -1){
				targetPositions = [pix-bmd.width*2-1,pix-bmd.width*2, pix-bmd.width*2+1, pix-bmd.width*2+2,
								   pix-bmd.width-1,pix-bmd.width, pix-bmd.width+1, pix-bmd.width+2,
								   pix-1,pix,pix+1, pix+2,
								   pix+bmd.width-1,pix+bmd.width,pix+bmd.width+1, pix+bmd.width+2]
			}else if(p.x == 2 && p.y == bmd.height){
				targetPositions = [pix-bmd.width*2-1, pix-bmd.width*2, pix-bmd.width*2+1, pix-bmd.width*2+2,
								   pix-bmd.width-1, pix-bmd.width, pix-bmd.width+1, pix-bmd.width+2,
								   pix-1, pix, pix+1, pix+2]
			}else if(p.x == bmd.width-1 && p.y == bmd.height -1){
				targetPositions = [pix-bmd.width*2-2, pix-bmd.width*2-1, pix-bmd.width*2, pix-bmd.width*2+1,
								   pix-bmd.width-2, pix-bmd.width-1, pix-bmd.width, pix-bmd.width+1,
								   pix-2,pix-1,pix, pix+1,
								   pix+bmd.width-2,pix+bmd.width-1, pix+bmd.width, pix+bmd.width+1]
			}else if(p.x == bmd.width && p.y == bmd.height -1){
				targetPositions = [pix-bmd.width*2-2, pix-bmd.width*2-1, pix-bmd.width*2,
								   pix-bmd.width-2, pix-bmd.width-1, pix-bmd.width,
								   pix-2,pix-1,pix,
								   pix+bmd.width-2,pix+bmd.width-1, pix+bmd.width]
			}else if(p.x == bmd.width-1 && p.y == bmd.height){
				targetPositions = [pix-bmd.width*2-2, pix-bmd.width*2-1, pix-bmd.width*2, pix-bmd.width*2+1,
								   pix-bmd.width-2, pix-bmd.width-1, pix-bmd.width, pix-bmd.width+1,
								   pix-2,pix-1,pix, pix+1]
			}else if(p.x == bmd.width && p.y == bmd.height){
				targetPositions = [pix-bmd.width*2-2, pix-bmd.width*2-1, pix-bmd.width*2,
								   pix-bmd.width-2, pix-bmd.width-1, pix-bmd.width,
								   pix-2,pix-1,pix]
			}else if(p.x >=3 && p.x <= bmd.width-2 && p.y == bmd.height){
				targetPositions = [pix-bmd.width*2-2, pix-bmd.width*2-1, pix-bmd.width*2, pix-bmd.width*2+1,pix-bmd.width*2+2,
								   pix-bmd.width-2, pix-bmd.width-1, pix-bmd.width,pix-bmd.width+1,pix-bmd.width+2,
								   pix-2,pix-1,pix,pix+1,pix+2]
			}else if(p.x >=3 && p.x <= bmd.width-2 && p.y == bmd.height-1){
				targetPositions = [pix-bmd.width*2-2, pix-bmd.width*2-1, pix-bmd.width*2, pix-bmd.width*2+1,pix-bmd.width*2+2,
								   pix-bmd.width-2, pix-bmd.width-1, pix-bmd.width,pix-bmd.width+1,pix-bmd.width+2,
								   pix-2,pix-1,pix,pix+1,pix+2,
								   pix+bmd.width-2,pix+bmd.width-1, pix+bmd.width,pix+bmd.width+1,pix+bmd.width+2]
			}else{
				targetPositions = [pix-bmd.width*2-2, pix-bmd.width*2-1, pix-bmd.width*2, pix-bmd.width*2+1, pix-bmd.width*2+2,
								   pix-bmd.width-2, pix-bmd.width-1, pix-bmd.width, pix-bmd.width+1, pix-bmd.width+2,
								   pix-2,pix-1,pix,pix+1,pix+2,
								   pix+bmd.width-2,pix+bmd.width-1, pix+bmd.width,
								   pix+bmd.width*2-2,pix+bmd.width*2-1, pix+bmd.width*2,pix+bmd.width*2+1,pix+bmd.width*2+2]
				
			}
			
			
			
			return avgColorWithArray(targetPositions);
			
		}
		
		private function avgColorWithArray(target:Array):Array{
			var a:int =0;
			var r:int =0;
			var g:int =0;
			var b:int =0;
			for(var i:int=0; i< target.length; i++){
				var ar:Array = argb(pixels[target[i] -1])
				a += ar[0];
				r += ar[1];
				g += ar[2];
				b += ar[3];
			}
			return [Math.floor(a/target.length), Math.floor(r/target.length), Math.floor(g/target.length), Math.floor(b/target.length)]
		}
		
		
		private function positionXY(p:uint):Point{
			var x:uint = p % bmd.width;
			if(x == 0) x = bmd.width;
			var y:uint = Math.ceil(p / bmd.width);
			return new Point(x,y);
		}
		
		private function argb(hex:uint):Array{
			var alpha:int  = hex >> 24 & 0xFF;
			var red:int    = hex >> 16 & 0xFF;
			var green:int  = hex >>  8 & 0xFF;
			var blue:int   = hex & 0xFF;
			return [alpha, red, green, blue];
		}
		
		private function hex(argb:Array):int{
			var color:uint;
			//color |= argb[0] << 24;
			color |= argb[1] << 16;
			color |= argb[2] <<  8;
			color |= argb[3];
			return int("0x"+color.toString(16));
			
		}
		
	
	}


}