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: forked from: 道っぽい表現のつもり

...
@author 393
道っぽい表現をつくりたかったけど
なんだかいまいちな感じ。。。

self fork
影で進行方向へのスピード感を出したかったのだけど
イマイチ伝わらない。。。

self fork
動きをマウスでインタラクティブに
目標の動きに近づいた感じ
/**
 * Copyright sakusan393 ( http://wonderfl.net/user/sakusan393 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/lujU
 */

// forked from sakusan393's 道っぽい表現のつもり
package  {
	/**
	 * ...
	 * @author 393
	 * 道っぽい表現をつくりたかったけど
	 * なんだかいまいちな感じ。。。
	 * 
	 * self fork
	 * 影で進行方向へのスピード感を出したかったのだけど
	 * イマイチ伝わらない。。。
	 * 
	 * self fork
	 * 動きをマウスでインタラクティブに
	 * 目標の動きに近づいた感じ
	 * 

	 */
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.BlendMode;
	import flash.display.GradientType;
	import flash.display.Graphics;
	import flash.display.InterpolationMethod;
	import flash.display.SpreadMethod;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.ColorTransform;
	import flash.geom.Matrix;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	[SWF(width=465, height=465, backgroundColor=0x666600, frameRate=30)]	

	public class Main extends Sprite {
		//private var stage_center_x:Number;
		//private var stage_center_y:Number;
		//private var stage_right_x:Number;
		//private var stage_bottom_y:Number;
		
		//ポイント座標格納用
		private var pointArray:Array;
		//private var top:Point;
		//private var left:Point;
		//private var right:Point;
		//private var bottom:Point;
		private var bmd:BitmapData;
		private var cTra:ColorTransform;
		private var rect:Rectangle;
		private var matrix:Matrix;
		private var speed:Number = 0;
		//private var prevX:Number;
		//private var prevY:Number;

		private var sp:Sprite;
		private var mousePoint:MousePoint;
		private var par:Number = 1;
		private var maxPoint:uint = 19;
		private var leftPoint:uint;
		private var ii:Number = 0;
		
		public function Main() {
			
			//ポイント座標の設定
			//var ratio:Number = 1.5;
			//var sideRatio:Number = 100;
			//rect = new Rectangle(0, 0, stage.stageWidth, stage.stageHeight);
			//matrix = new Matrix();
			//基本三角形の座標
			//top = new Point(0,stage.stageHeight/2);
			//left = new Point(0+stage.stageWidth/sideRatio,stage.stageHeight*ratio);
			//right = new Point(stage.stageWidth-stage.stageWidth/sideRatio,stage.stageHeight*ratio);
			//stage_center_x = stage.stageWidth/2;
			//stage_center_y = stage.stageHeight/2;
			//stage_right_x = stage.stageWidth;
			//setPoint();
			//var sp:Sprite  = new Sprite();
			//sp.blendMode = BlendMode.SCREEN;
			//sp.x = stage.stageWidth;
			//sp.y = stage.stageHeight;
			//prevX = sp.x;
			//prevY = sp.y;
			//bmd = new BitmapData(stage.stageWidth,stage.stageHeight,false, 0x00000000);
			//var bm:Bitmap = new Bitmap(bmd);
			//addChild(bm);
			//addChild(sp);
			//sp.addEventListener(Event.ENTER_FRAME , enterFrameHandler);
			
			rect = new Rectangle(0, 0, stage.stageWidth, stage.stageHeight);
			matrix = new Matrix();
			cTra = new ColorTransform( 1, 1, .8, 1);
			
			//マウスポイント用オブジェクト
			mousePoint = new MousePoint();
			addChild(mousePoint);
			
			//左側のポイント数
			leftPoint = Math.ceil(maxPoint / 2);
			//ポイント格納用配列
			pointArray = [];
			for (var i:Number = 0; i < maxPoint; i++){
				pointArray.push(new CustomPoint(this.stage.stageWidth, this.stage.stageHeight));
			}
			sp = new Sprite();
			addChild(sp);
			sp.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
		}
		
		private function enterFrameHandler(e:Event = null ):void {
			
			//var sp:Sprite = e.target as Sprite;
			//var spg:Graphics = sp.graphics;
			//spg.clear();
			//spg.beginGradientFill(GradientType.RADIAL,
				//[0xFFFFcc , 0xFFFFcc , 0xFFFF33 , 0xFFFF00 , 0xCCCC00],
				//[ 1 , 1 ,  1 ,  1 , 1],
				//[ 0 , 64, 127 , 192 , 255],
				//new Matrix(
					//1 , 0 ,
					//0 , 1 ,
					//top.x , top.y
				//),
				//SpreadMethod.PAD,
				//InterpolationMethod.LINEAR_RGB,
				//0.0
			//);
			//spg.moveTo(pointArray[0].posX, pointArray[0].posY);
			//for (var i:uint = 1; i < pointArray.length-1; i++){
				//spg.curveTo(pointArray[i].posX, pointArray[i].posY,(pointArray[i].posX + pointArray[i+1].posX)/2, (pointArray[i].posY + pointArray[i+1].posY)/2);
			//}
			//spg.curveTo(pointArray[pointArray.length-1].posX, pointArray[pointArray.length-1].posY,pointArray[0].posX, pointArray[0].posY);
			//spg.endFill();
			//move(sp);
			
			var sp:Sprite = e.target as Sprite;
			//マウスポイント用のオブジェ
			//直接マウスポインタを追いかけさせるのではなく、ワンクッション的なもの
			mousePoint.x += (this.mouseX - mousePoint.x)*0.1;
			mousePoint.y += (this.mouseY - mousePoint.y) * 0.1;
			
			var targetX:Number
			var targetY:Number
			var ax:Number
			var ay:Number
			
			//三角形左辺側の作成
			for (var i:Number = 0; i < leftPoint; i++ ) {
				
				//一個目のポイントはマウスポインタオブジェから加速度を設定。
				if (i == 0) {
					targetX = mousePoint.x
					targetY = mousePoint.y
					
					ax = (targetX - pointArray[i].posX) * par;
					ay = (targetY - pointArray[i].posY) * par;
					
					pointArray[i].setKasokudo(ax, ay);
				}
				//2個目以降のポイントは一個前のポイントから加速度を設定
				else {
					targetX = pointArray[i-1].posX;
					targetY = pointArray[i-1].posY;
					ax = (targetX - pointArray[i].posX) * par/i*2 - i*6;
					ay = (targetY - pointArray[i].posY) * par/i;
					
					pointArray[i].setKasokudo(ax, ay);
				}
			}
			ii = 2;
			//三角形右辺側の作成
			for (i = maxPoint-1; i >= leftPoint; i--) {
				if (i == maxPoint-1) {
					targetX = mousePoint.x
					targetY = mousePoint.y
					
					ax = (targetX - pointArray[i].posX) * par;
					ay = (targetY - pointArray[i].posY) * par/1;
					
					pointArray[i].setKasokudo(ax, ay);
				}
				else {
					targetX = pointArray[i+1].posX;
					targetY = pointArray[i+1].posY;
					
					ax = (targetX - pointArray[i].posX) * par/ii*2 + ii*(20-ii*3);
					ay = (targetY - pointArray[i].posY) * par/ii;
					pointArray[i].setKasokudo(ax, ay);
					ii++;
				}

			}
			sp.graphics.clear();
			sp.graphics.lineStyle(2, 0xFFFF33);
			
			drawCurve(pointArray, sp);
			
			var bm:CustomBitmap = new CustomBitmap(bmd);
			bmd = new BitmapData(stage.stageWidth, stage.stageHeight, true, 0x00000000);
			bmd.draw(sp,matrix);
			bmd.colorTransform(rect,cTra);
			addChildAt(bm, 1);
			bm.x = 5
			bm.y = 20
			bm.addEventListener("dispose", dispose);
		}
		
		//private function move(sp:Sprite):void{
			//speed += 10;
			//var radian:Number = degreeToRadian(speed);
			//固定的な動き
			//sp.x = 60 * Math.sin(radian) + stage_center_x;
			//sp.y = 80 * Math.cos(radian / 10);
			//
			//マウスに反応
			//sp.x += ((mouseX + 100) - prevX)*0.05;
			//sp.y += ((mouseY -stage.stageHeight / 2 + 50) - prevY) * 0.05;
			//prevX = sp.x;
			//prevY = sp.y;
			//
                        //残像用
			//matrix.tx = sp.x;
			//matrix.ty = sp.y;
			//
			//bmd.draw(sp, matrix, cTra);
			//bmd.colorTransform(rect, cTra);
			//matrix.tx = sp.x;
			//matrix.ty = sp.y;
			//
			//var bm:CustomBitmap = new CustomBitmap(bmd);
			//bmd = new BitmapData(stage.stageWidth, stage.stageHeight, true, 0x00000000);
			//bmd.draw(sp,matrix);
			//bmd.colorTransform(new Rectangle(0, 0, stage.stageWidth, stage.stageHeight),cTra);
			//addChildAt(bm, 1);
			//bm.x = 5
			//bm.y = 20
			//bm.addEventListener("dispose", dispose);
		//}
		private function dispose(e:Event):void {
			removeChild(Bitmap(e.target));
		}
		public  function drawCurve(pointArray: Array, sp: Sprite):void {
			//ポイントの座標の計算
			//sp.graphics.beginFill(0xFFFF00);
			sp.graphics.beginGradientFill(GradientType.RADIAL,
				[0xFFFFcc , 0xFFFFcc , 0xcccc33 , 0x999933 , 0x666600],
				[ 1 , 1 ,  1 ,  1 , 1],
				[ 0 , 64, 127 , 192 , 255],
				new Matrix(
					1 , 0 ,
					0 , 1 ,
					sp.mouseX , sp.mouseY
				),
				SpreadMethod.PAD,
				InterpolationMethod.LINEAR_RGB,
				0.0
			);
			if (pointArray.length > 2) {
				sp.graphics.moveTo(pointArray[0].posX, pointArray[0].posY);  
				for (var i:Number = 1; i < pointArray.length - 1; i++){
					sp.graphics.curveTo(
						pointArray[i].posX, 
						pointArray[i].posY, 
						(pointArray[i].posX + pointArray[i + 1].posX) / 2, 
						(pointArray[i].posY + pointArray[i + 1].posY) / 2
						);      
				}
				sp.graphics.curveTo(
					pointArray[pointArray.length - 1].posX, 
					pointArray[pointArray.length - 1].posY, 
					pointArray[0].posX, 
					pointArray[0].posY
					);
				sp.graphics.endFill();
			}  
		}

		//private function degreeToRadian(degree:Number ):Number{
			//var radian = degree * (Math.PI / 180);
			//return radian;
		//}
		//private function setPoint():void{
			//pointArray = new Array();
			//pointArray.push(new CustomPoint(top.x, top.y, 100, 80, 5,2,0))
			//pointArray.push(new CustomPoint(top.x -(top.x-left.x)*1/6,top.y-(top.y-left.y)*1/6,200,30,5,4,-30))
			//pointArray.push(new CustomPoint(top.x -(top.x-left.x)*2/6,top.y-(top.y-left.y)*2/6,250,60,5,3,-60))
			//pointArray.push(new CustomPoint(top.x -(top.x-left.x)*3/6,top.y-(top.y-left.y)*3/6,300,90,5,2,-90))
			//pointArray.push(new CustomPoint(top.x -(top.x-left.x)*4/6,top.y-(top.y-left.y)*4/6,300,90,5,2,-120))
			//pointArray.push(new CustomPoint(top.x -(top.x-left.x)*5/6,top.y-(top.y-left.y)*5/6,300,90,5,2,-150))
			//pointArray.push(new CustomPoint(left.x,left.y,300,10,5,5, -120))
			//pointArray.push(new CustomPoint(right.x,right.y,300,10,5,5,-120))
			//pointArray.push(new CustomPoint(top.x -(top.x-right.x)*5/6,top.y-(top.y-right.y)*5/6,300,90,5,2,-150))
			//pointArray.push(new CustomPoint(top.x -(top.x-right.x)*4/6,top.y-(top.y-right.y)*4/6,250,60,5,3,-120))
			//pointArray.push(new CustomPoint(top.x -(top.x-right.x)*3/6,top.y-(top.y-right.y)*3/6,200,30,5,4,-90))
			//pointArray.push(new CustomPoint(top.x -(top.x-right.x)*2/6,top.y-(top.y-right.y)*2/6,200,30,5,4,-60))
			//pointArray.push(new CustomPoint(top.x -(top.x-right.x)*1/6,top.y-(top.y-right.y)*1/6,200,30,5,4,-30))
		//}
	}
}
import flash.events.Event;
import flash.geom.Point;
import flash.display.*;

import flash.filters.BlurFilter;
import flash.utils.Timer;
import flash.events.TimerEvent;

//class CustomPoint extends Sprite {
class CustomPoint {
	private var _posX:Number;
	private var _posY:Number;
	//private var _radiusX:Number;
	//private var _radiusY:Number;
	//private var degreeSpeedX:Number = 0;
	//private var degreeSpeedY:Number = 0;
	//private var defoPosX:Number;
	//private var defoPosY:Number;
	//private var speed:Number;
	//private var _speedX:Number;
	//private var _speedY:Number;
	
	private var spring:Number = .06;
	private var friction:Number =.8;
	private var vx:Number = 0;
	private var vy:Number = 0;
	private var ax:Number = 0;
	private var ay:Number = 0;
	private var gravityX:Number = 1;
	private var gravityY:Number = 1;
	
	//public function CustomPoint(posX:Number,posY:Number,radiusX:Number = 100,radiusY:Number = 100,speedX:Number = 15, speedY:Number = 15, delay:Number = 0):void {
		//_posX = defoPosX = posX;
		//_posY = defoPosY = posY;
		//_speedX = speedX;
		//_speedY = speedY;
		//degreeSpeedX += delay;
		//degreeSpeedY += delay;
		//
		//_radiusX = radiusX;
		//_radiusY = radiusY;
		//speed = 5;
		//addEventListener(Event.ENTER_FRAME, enterFrameHandler);
	//}
	
	public function CustomPoint(posX:Number, posY:Number) {
		_posX = posX;
		_posY = posY;
		var timer:Timer = new Timer(33);
		timer.addEventListener(TimerEvent.TIMER, timerHandler);
		timer.start();
	}
	
	private function timerHandler(e:TimerEvent):void {
		ax = ax * spring;
		vx += ax;
		vx += gravityX;
		vx *= friction;
		_posX += vx;
		
		ay = ay * spring;
		vy += ay;
		vy += gravityY;
		vy *= friction;
		_posY += vy;
		
	}
	public function setKasokudo(aax:Number, aay:Number):void {
		ax = aax;
		ay = aay;
	}
	
	//private function enterFrameHandler(e:Event):void {
		//degreeSpeedX += _speedX;
		//degreeSpeedY += _speedY;
		//var radianX = degreeToRadian(degreeSpeedX);
		//var radianY = degreeToRadian(degreeSpeedY);
		//_posX = _radiusX * Math.sin(radianX/.8) + defoPosX;
		//_posY = _radiusY * Math.cos(radianY/.8) + defoPosY;
	//}
	
	//private function degreeToRadian(degree:Number ):Number{
		//var radian = degree * (Math.PI / 180);
		//return radian;
	//}
	
	public function get posX():Number { return _posX; }
	
	//public function set posX(value:Number):void{
		//_posX = value;
	//}
	
	public function get posY():Number { return _posY; }
	
	//public function set posY(value:Number):void{
		//_posY = value;
	//}
	
}
class CustomBitmap extends Bitmap {
	public function CustomBitmap(bmd:BitmapData):void {
		super(bmd);
		addEventListener(Event.ENTER_FRAME, enterFrameHandler);
	}
	
	private function enterFrameHandler(e:Event):void {
		x+= 5;
		y+= 20;
		alpha -= .3
		if (alpha <= 0){
			removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
			dispatchEvent(new Event("dispose"));
		}
	}
}
class MousePoint extends Sprite {
	
	private var speed:Number;
	
	function MousePoint():void {
		graphics.beginFill(0xdddd00);
		graphics.drawCircle(0, 0, 300);
		graphics.endFill();
		var blur = new BlurFilter(300, 300,2);
		this.filters = [blur];
		speed = 0;
		addEventListener(Event.ENTER_FRAME, enterFrameHandler);
	}
	
	private function enterFrameHandler(e:Event):void {
		speed += Math.random() * 0.2;
		var radiusX:Number = Math.random() * 10;
		var radiusY:Number = Math.random() * 10;
		x += radiusX+Math.sin(speed)*radiusX;
		y += radiusY+Math.cos(speed/2)*radiusY;
	}
	
}