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

After Image

最適化してないんで、すげー重いです。
やっぱり尾はbmpにしないと…
Get Adobe Flash player
by sandmanjp 17 Feb 2010
/**
 * Copyright sandmanjp ( http://wonderfl.net/user/sandmanjp )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/7SFS
 */

//最適化してないんで、すげー重いです。
//やっぱり尾はbmpにしないと…
package {
    import flash.display.Sprite;
    import flash.display.Shape;
	import flash.events.Event;
	
	[SWF(width="464", height="464",backgroundColor="#000000",frameRate="30")]
	
    public class Main extends Sprite {
        public function Main():void {
            
			for(var i:int=0; i < 3; i++){
				addChild(createAI(i));
			}
			
        }
        
        
		public function createAI(n:int):AfterImage{
			var af:AfterImage = new AfterImage();
			
			af.speed = 20 + (10 * n);
			
			af.core.addEventListener(Event.ENTER_FRAME, function(e:Event):void{
				var tgt:Shape = e.target as Shape;
				
				tgt.x += (mouseX - tgt.x) / af.speed;
				tgt.y += (mouseY - tgt.y) / af.speed;
			})
			
			af.startAI();
			
			return af;
			
		}
		
	}

}

import flash.display.Shape;
import flash.display.Sprite;
import flash.display.BlendMode;
import flash.events.Event;
import flash.geom.Point;
import flash.geom.Matrix;
import flash.filters.GlowFilter;

class AfterImage extends Sprite {
	
	private var _pos_arr:Array = new Array();
	private const MAX_POS:int = 5;
	
	public var core:Shape;
	
	public var speed:Number;
	
	function AfterImage():void {
		blendMode = BlendMode.SCREEN;
		filters = new Array(new GlowFilter(0xFF9900, 1, 10, 10, 3, 1))
		core = CoreLight.getLight();
		addChild(core);
	}
	
	public function startAI():void {
		addEventListener(Event.ENTER_FRAME, enterframeHandler);
	}
	
	private function enterframeHandler(e:Event):void {
		
		if(!Boolean(core)){
			return;
		}
		
		_pos_arr.push({x:core.x, y:core.y, width:core.width, height:core.height});
		
		if(_pos_arr.length > MAX_POS){
			_pos_arr.shift();
		}
		
		drawAI();
	}
	
	private function AIEnterframeHandler(e:Event):void {
		var ai:Sprite = Sprite(e.target);
		
		ai.alpha += (0 - ai.alpha) / 50
		
		if(ai.alpha < 0.1){
			ai.removeEventListener(Event.ENTER_FRAME, AIEnterframeHandler);
			removeChild(ai);
		}
	}
	
	private function drawAI():void {
		if(_pos_arr.length < 2){
			return;
		}
		
		var line:Sprite = createAI(_pos_arr[_pos_arr.length - 1], _pos_arr[_pos_arr.length - 2]);
		
		addChildAt(line, 0);
	}
	
	private function createAI(c0:Object, c1:Object):Sprite {
		
		var x0:Number = c0.x - c1.x;
		var y0:Number = c0.y - c1.y;
		
		var r:Number = Math.atan(y0 / x0);
		var degree:Number = r * 180 / Math.PI;
		
		
		var pa0:Point = new Point(c0.x + (Math.sin(r) * (c0.width / 2)), c0.y - (Math.cos(r) * (c0.height / 2)))
		var pa1:Point = new Point(c1.x + (Math.sin(r) * (c1.width / 2)), c1.y - (Math.cos(r) * (c1.height / 2)))
		
		var pb0:Point = new Point(c0.x - (Math.sin(r) * (c0.width / 2)), c0.y + (Math.cos(r) * (c0.height / 2)))
		var pb1:Point = new Point(c1.x - (Math.sin(r) * (c1.width / 2)), c1.y + (Math.cos(r) * (c1.height / 2)))
		
		//コントロールポイント手前
		
		//直角三角形の定理から距離を出す
		var margin:Number = Math.pow(Math.abs(pa0.x - pb0.x), 2) + Math.pow(Math.abs(pa0.y - pb0.y), 2);
		
		var long:Number = Math.sqrt(margin/2);
		
		
		var pr0:Number = c0.x >= c1.x ? (degree - 90) * Math.PI / 180 : (degree + 90) * Math.PI / 180;
		var pp0:Point = new Point(c0.x + (Math.sin(pr0) * long), c0.y - (Math.cos(pr0) * long));
		
		var pr1:Number = c0.x >= c1.x ? (degree + 90) * Math.PI / 180 : (degree - 90) * Math.PI / 180;
		var pp1:Point = new Point(c1.x - (Math.sin(pr1) * long), c1.y + (Math.cos(pr1) * long));
		
		var line:Sprite = new Sprite();
		
		line.graphics.beginFill(0xFFFF00 ,0.5);
		
		line.graphics.moveTo(pa0.x, pa0.y);
		line.graphics.lineTo(pa1.x, pa1.y);
		line.graphics.curveTo(pp1.x, pp1.y, pb1.x, pb1.y);
		line.graphics.lineTo(pb0.x, pb0.y);
		line.graphics.curveTo(pp0.x, pp0.y, pa0.x, pa0.y);
		line.graphics.endFill();
		
		
		line.addEventListener(Event.ENTER_FRAME, AIEnterframeHandler);
		
		return line;
	}
	
	
}

class CoreLight {
	
	import flash.display.Shape;
	import flash.filters.GlowFilter;
	
	public function CoreLight():void {
		
	}
	static public function getLight():Shape {
		
		var px:Number = 0;		// 中心 y 座標
		var py:Number = 0;		// 中心 x 座標
		var radius:Number = 2;		// 半径
		var num:int = 3;		// 頂点数
		
		var shape:Shape = new Shape();
		
		shape.graphics.beginFill (0xFFFF00, 1.0);	// 面のスタイル設定
		
		shape.graphics.moveTo (px + radius, py);
		for(var i:int=0;i < num;i++){
			var rad:Number = i / num * Math.PI * 2;
			shape.graphics.lineTo(
				px + Math.cos(rad) * radius,
				py + Math.sin(rad) * radius
			);
		}
		
		shape.graphics.endFill();
		
		//shape.blendMode = BlendMode.SCREEN;
		shape.filters = CoreLight.createFilters();
		
		return shape;
	}
	
	static public function createFilters():Array {
		
		var glow:GlowFilter = new GlowFilter(0xFFFF00, 1, 5, 5, 10, 2);
		
		return new Array(glow)
	}
	
}