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: After Image

/**
 * Copyright sandmanjp ( http://wonderfl.net/user/sandmanjp )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/bf7O
 */

// forked from sandmanjp's After Image

package {
    import flash.display.*;
	import flash.events.Event;
	import flash.filters.GlowFilter;
	import flash.geom.*;
	
	[SWF(width="464", height="464",backgroundColor="0",frameRate="30")]
	
    public class Main extends Sprite {
		private var canvas:BitmapData;
		private var canvas_bmp:Bitmap;
		private var ad_arr:Array = new Array();
		
        public function Main():void {
        		canvas = new BitmapData(464, 464, true, 0x000000);
			canvas_bmp = new Bitmap(canvas);
			canvas_bmp.filters = new Array(new GlowFilter(0xFF9900, 1, 10, 10, 3, 1))
			addChild(canvas_bmp);
			
			for(var i:int=0; i < 3; i++){
				ad_arr[i] = createAI(i);
				addChild(ad_arr[i].core);
			}
			
			addEventListener(Event.ENTER_FRAME, update);
        }
        
        
		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;
			})
			
			return af;
		}
		
		public function draw():void{
			var len:int = ad_arr.length;
			canvas.lock();
			for(var i:int=0; i < len; i++){
				var line:Sprite = ad_arr[i].drawAI();
				canvas.draw(line);
			}
			canvas.unlock();
		}
		
		private function update(e:Event):void {
			canvas.colorTransform(canvas.rect, new ColorTransform(1, 1, 1, 0.97, 0, 0, 0, 0));
			draw();
		}
		
	}

}

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 {
	
	private var _pos_arr:Array = new Array();
	private const MAX_POS:int = 2;
	
	private 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();
		_core.blendMode = BlendMode.SCREEN;
		//addChild(core);
	}
	
	public function get core():Shape {
		return _core;
	}
	
	public function drawAI():Sprite {
		_pos_arr.push({x:_core.x, y:_core.y, width:_core.width, height:_core.height});
		
		if(_pos_arr.length > MAX_POS){
			_pos_arr.shift();
		}else if(_pos_arr.length < 2){
			return new Sprite();
		}
		
		return createAI(_pos_arr[_pos_arr.length - 1], _pos_arr[_pos_arr.length - 2]);
	}
	
	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.lineStyle(0.1, 0xFFFF00, 0.1)
		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();
		
		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 (0xFFFFFF, 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.filters = new Array(new GlowFilter(0xFF9900, 1, 8, 8, 10, 2));
		
		return shape;
	}
	
}