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: forked from: flash on 2009-11-1

マウスのまわりをラインがうねうねをdraw
@author ibu4gin
いろいろぱくってます

Gradation クラス 使いました
http://wonderfl.net/code/7ed2d650b9d513edf9a499fb704c19ecb7aa4694

スライダーで色かえたいけどおかしい?
frocessing.color.ColorBlendが気になる
なおった
配列の入れ替えがおかしかった!
Get Adobe Flash player
by ibu4gin 05 Nov 2009
    Embed
/**
 * Copyright ibu4gin ( http://wonderfl.net/user/ibu4gin )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/33jr
 */

// forked from ibu4gin's forked from: forked from: flash on 2009-11-1
// forked from ibu4gin's forked from: flash on 2009-11-1
// forked from ibu4gin's flash on 2009-11-1
/*
マウスのまわりをラインがうねうねをdraw
@author ibu4gin
いろいろぱくってます

Gradation クラス 使いました
http://wonderfl.net/code/7ed2d650b9d513edf9a499fb704c19ecb7aa4694

スライダーで色かえたいけどおかしい?
frocessing.color.ColorBlendが気になる
なおった
配列の入れ替えがおかしかった!

*/
package {
	import flash.display.Sprite;
	import flash.display.Graphics;
	import flash.display.Shape;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.BlendMode;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.geom.Matrix;
	import flash.geom.ColorTransform;
	import flash.filters.ColorMatrixFilter;
	import flash.filters.BlurFilter;
	
	import frocessing.color.ColorRGB;
	//import frocessing.color.ColorBlend;
	import com.bit101.components.HUISlider;
	
	public class line extends Sprite
	{
		private var pptArr     :Array = [];
		private var canvas     :BitmapData;
		private var bmp        :Bitmap;
		private var line_base  :Sprite;
		private var canvas_base:Sprite;
		private var test_flg   :Boolean = false;
		private var S_W        :Number;
		private var S_H        :Number;
		
		private var blend_col  :uint;
		
		private var col_0      :uint = 0x3976AA;
		private var col_465    :uint = 0x34AD83;
		
		private var grad:Gradation;
		private var _ColorRGB_arr:Array = [];
		private var _ColorRGB_0  :ColorRGB;
		private var _ColorRGB_465:ColorRGB;
		
		private var HUISlider_arr:Array = []; 
		//test
		private var col_bmp:Bitmap;
		
		
		public function line():void
		{
			stage.frameRate = 60;
			S_W = 465;
			S_H = 465;
			
			line_base   = new Sprite(); 
			canvas_base = addChild( new Sprite() ) as Sprite; 
			
			canvas = new BitmapData(S_W,S_H,true,0x00FFFFFF);//0x00
            bmp    = new Bitmap( canvas );
			canvas_base.addChild( bmp );
			
			
			for(var v:uint = 0;  v < pptNUM; ++v)pptArr[v] = new PhyPo(S_W/2, S_H/2);
			
			if(test_flg) addChild( line_base );
			
			
			grad = new Gradation( col_0 ,col_465 );
			
			_ColorRGB_0   = new ColorRGB(); _ColorRGB_0.value   = col_0;
			_ColorRGB_465 = new ColorRGB(); _ColorRGB_465.value = col_465;
			
			_ColorRGB_arr[0] = _ColorRGB_0;
			_ColorRGB_arr[1] = _ColorRGB_465;
			
			
			_Slider();
			
			//blend_col = ColorBlend.add( 0x3976AA, 0xDAD903);
			//blend_col = ColorBlend.blend( 0x3976AA, 0xDAD903, ColorBlend.HARDLIGHT );
			//col_bmp = canvas_base.addChild( new Bitmap( new BitmapData(10,10,false,0xffffff) as BitmapData) ) as Bitmap;
			
			
			addEventListener(Event.ENTER_FRAME, render)
		}
		
		
		
		
		
		// レンダリング
		private function render(E:Event):void
		{
			
			Line_Loop();
			
			if(!test_flg){
			
			bmpDraw();
			
			fadeStep();
			
			}
			
		}
		
		
		// フィルターetc
		private var mat     :Matrix;
		private var rota_num:Number;
		private var po      :Point             = new Point();
		private var BLURFil :BlurFilter        = new BlurFilter(4,4,2);
		//private var ColorTR :ColorTransform    = new ColorTransform(Math.random()*0.4+0.6,Math.random()*0.4+0.6,Math.random()*0.4+0.6,1,0,0,0,0);
		private var CoMatFil:ColorMatrixFilter = new ColorMatrixFilter([2,   0,   0,   0,   -100, 0,   2,   0,   0,   -100,	0,   0,   2,   0,   -100,0,   0,   0,   1,   0]);
		private var ColorTR :ColorTransform = new ColorTransform(100,100,100,100,0,0,0,0);
		
		
		private function bmpDraw():void
		{
			canvas.draw(line_base, mat, null, BlendMode.ADD, null, true);
		}
		
		
		public function fadeStep():void
        {
			canvas.applyFilter(canvas, canvas.rect, po, BLURFil);
			//canvas.applyFilter(canvas, canvas.rect, po, CoMatFil)
			//canvas.colorTransform(canvas.rect, );
        }
				
		
		// ライン生成
		private var KN        :Number = 4;
		private var tenPo_X   :Number = 0;
		private var tenPo_Y   :Number = 0;
		private var hankei    :Number = 100;
		private var angle     :Number = 0;
		private var yuragi_num:Number = 0;
		private var my_byo    :Number = 0;	
		//ラインのポイント数
		private var pptNUM    :int    = 10;//10
		
		private var mouseXX:Number;
		private var mouseYY:Number;
		
		private function Line_Loop(E:Event = null):void
		{
			
			my_byo += 0.02;
			yuragi_num =  -5000 * Math.sin( my_byo * Math.PI * 2 * 0.1 );
			yuragi_num = yuragi_num | 0;
			angle += 0.00001 * yuragi_num;
			
			
			if( hankei < 300 ){//400
				hankei += 1;
			}
			
			mouseXX = mouseX-50;
			mouseYY = mouseY+50;
			//mouseXX = (S_W/2 -50);
			//mouseYY = (S_H/2 +50);
			
			tenPo_X = mouseXX + hankei * Math.cos( angle + Math.PI * 2 );
			tenPo_Y = mouseYY + hankei * Math.sin( angle + Math.PI * 2 );
			
			for(var v:uint =0; v < pptNUM; v++){
				
				pptArr[v].Loop();
				
				if(v == 0){
					pptArr[v].SET_kasokudo( ( tenPo_X - pptArr[v].X) * (KN+15), ( tenPo_Y - pptArr[v].Y) * (KN+40) );//(KN+20)
				}else{
					pptArr[v].SET_kasokudo( ( pptArr[v-1].X - pptArr[v].X) * KN, ( pptArr[v-1].Y - pptArr[v].Y) * KN);//KN-4
				}
			}
			
			//ライン生成
			line_base.graphics.clear();
			line_base.graphics.lineStyle( 1 , grad.getColor(tenPo_Y / 464));
			DrawCurve( pptArr, line_base);
			
			/*var poji:Number = mouseY / 464;
			ColorTR.redOffset   = grad.getColor(poji) >> 16 & 0xff;
			ColorTR.greenOffset = grad.getColor(poji) >> 8 & 0xff;
			ColorTR.blueOffset  = grad.getColor(poji) & 0xff;
			col_bmp.transform.colorTransform = ColorTR;*/
		}
		
		
		
		private function DrawCurve( Arr:Array, SP:Sprite ):void
		{
			var num:int = Arr.length;
			
			if(num >= 3){
				SP.graphics.moveTo(Arr[1].X,Arr[1].Y);
				
				for(var v:uint = 1; v <= num-3; v++){
					SP.graphics.curveTo(Arr[v].X,Arr[v].Y,(Arr[v].X+Arr[v+1].X)/2,(Arr[v].Y+Arr[v+1].Y)/2);
				}
				
				SP.graphics.curveTo(Arr[num-2].X,Arr[num-2].Y,Arr[num-1].X,Arr[num-1].Y);
			}
		}//DrawCurve
		
		
		
		
		private function _Slider():void
		{
			for(var n:int = 0; n < 3; n++ ){
				
				HUISlider_arr[n] = new HUISlider( canvas_base, 10, 400+(n*20), String(n), _onChangeRGB);
				HUISlider_arr[n].minimum = 0;
				HUISlider_arr[n].maximum = 255;
				
				if(n==0){
					HUISlider_arr[n].value   = _ColorRGB_arr[0].r;
				}else if(n==1){
					HUISlider_arr[n].value   = _ColorRGB_arr[0].g;
				}else{
					HUISlider_arr[n].value   = _ColorRGB_arr[0].b;
				}
			}
			
			for( n = 3; n < 6; n++ ){
				HUISlider_arr[n] = new HUISlider( canvas_base,280, 400+((n-3)*20), String(n), _onChangeRGB);
				HUISlider_arr[n].minimum = 0;
				HUISlider_arr[n].maximum = 255;
				if(n==3){
					HUISlider_arr[n].value   = _ColorRGB_arr[1].r;
				}else if(n==4){
					HUISlider_arr[n].value   = _ColorRGB_arr[1].g;
				}else{
					HUISlider_arr[n].value   = _ColorRGB_arr[1].b;
				}
			}
		}
		
		
		
		private function _onChangeRGB(E:Event):void
		{
			var NUM:int = int(E.target.label);
			
			HUISlider_arr[NUM].value = HUISlider_arr[NUM].value | 0;
			
			var col:uint;
			
			if(NUM < 3){
				
				if(NUM == 0)_ColorRGB_arr[0].r = HUISlider_arr[NUM].value;
				if(NUM == 1)_ColorRGB_arr[0].g = HUISlider_arr[NUM].value;
				if(NUM == 2)_ColorRGB_arr[0].b = HUISlider_arr[NUM].value;
				
				col   = _ColorRGB_arr[0].r << 16 | _ColorRGB_arr[0].g << 8 | _ColorRGB_arr[0].b;
				col_0 = col;
				
				grad.colors(  col_0, col_465 );
				
			}else{
				if(NUM == 3)_ColorRGB_arr[1].r = HUISlider_arr[NUM].value;
				if(NUM == 4)_ColorRGB_arr[1].g = HUISlider_arr[NUM].value;
				if(NUM == 5)_ColorRGB_arr[1].b = HUISlider_arr[NUM].value;
				
				col     = _ColorRGB_arr[1].r << 16 | _ColorRGB_arr[1].g << 8 | _ColorRGB_arr[1].b;
				col_465 = col;
				
				grad.colors( col_0, col_465 );
			}
		}
		
		
		
	}//class
}//package


////////////////////////////////
class PhyPo
{
	public  var X:Number, Y:Number;
	private var vX:Number, vY:Number;
	private var aX:Number, aY:Number;
	private var B:Number;
	private var t:Number = 0.02;
	public function set _t( value:Number ):void{ _t = value; }
	private var add_t:Number = 0.5;
	public function set _add_t( value:Number ):void{ _add_t = value; }

	public function PhyPo(XX:Number = 0, YY:Number = 0):void
	{
		X  = XX;
		Y  = YY;
		B  = 0.9;
		vX = 0;
		vY = 0;
		aX = 0;
		aY = 0;
	}
	
	public function Loop():void
	{
		var XXX:Number = vX *t + add_t * aX * t * t;
		var YYY:Number = vY *t + add_t * aY * t * t;
		
		X += XXX;
		Y += YYY;
		
		X += vX *t + add_t * aX * t * t;
		Y += vY *t + add_t * aY * t * t;

		vX += aX * t;
		vY += aY * t;
		
		vX *= B;
		vY *= B;
		
		aX = 0;
		aY = 0;
	}//

	public function SET_kasokudo(aaX:Number = 0,aaY:Number = 0):void
	{
		aX += aaX;
		aY += aaY;
	}
			
}



////////////////////////////////
import frocessing.color.ColorLerp;
import org.libspark.betweenas3.core.easing.IEasing;
import org.libspark.betweenas3.easing.Linear;

class Gradation {
    
    private var _colors:Array;
	
	public function colors(...args):void{
		_colors = null;
		_colors = [];
		_colors = args.concat();
	}
	
	private var _easing:IEasing;
	
    public function Gradation(...args) {
        _colors = args.concat();
		_easing = Linear.linear;
    }
    
    public function setEasing(easing:IEasing):void{
        _easing = easing;
    }
	
    public function getColor(position:Number):uint {
		position    = ( position < 0 ? 0 : position > 1 ? 1 : position ) * ( _colors.length - 1 );
		
        var idx:int =  position;
		
        var alpha:Number = _easing.calculate( position - idx, 0, 1, 1);
		
		if( alpha == 0) {
            return _colors[idx];
        } else {
            return ColorLerp.lerp( _colors[idx], _colors[idx + 1], alpha);
        }
    }
	
	
	
}//class