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

二つのうねうね

...
@author DefaultUser (Tools -> Custom Arguments...)
Get Adobe Flash player
by fumix 02 Jun 2009
/**
 * Copyright fumix ( http://wonderfl.net/user/fumix )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/rSLP
 */

package 
{
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.Event;
	
	/**
	 * ...
	 * @author DefaultUser (Tools -> Custom Arguments...)
	 */
    [SWF(width = "465", height = "465", frameRate = "30", backgroundColor = "#ffffff")]
	public class Main extends Sprite 
	{
		
		
		
		
		/**
		 * コンストラクタ
		 */
		public function Main():void 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
			var r1:ribbon = new ribbon(false,0xCCCCCC,18);
			var r2:ribbon = new ribbon(true,0xAAAAAA,15);
			r1.x = stage.stageWidth / 2;
			r2.x = stage.stageWidth / 2+4;
			addChild(r1);
			addChild(r2);
		}
	}
	
}
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.Event;
	
	/**
	 * ...
	 * @author DefaultUser (Tools -> Custom Arguments...)
	 */
	class ribbon extends Sprite 
	{
		private const MAXNUMBER:int = 100;
		private const WIDTH:int = 14;
		
		private var widthPiece:Number;
		private var offsetX:Number;
		private var offsetY:Number;
		private var color:uint;
		
		private var rad1:Number;
		private var rad2:Number;
		private var drad1:Number;

		private var rollDirection:int;
		
		
		private var Sprites:Array;
		
		
		
		
		/**
		 * ウネウネするリボン
		 * @リボンの振り幅		_widthPiece
		 * @x座標のオフセット	_offsetX
		 * @y座標のオフセット	_offsetY
		 * @y回転方向(右左)	_roll
		 */
		public function ribbon(_roll:Boolean=true, _color:uint=0x000000,_widthPiece:Number=15,_offsetX:Number=0,_offsetY:Number=0):void 
		{
			//初期値設定
			if (_roll) rollDirection = 1;
			else rollDirection = -1;
			color = _color;
			widthPiece = _widthPiece;
			offsetX = _offsetX;
			offsetY = _offsetY;

			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
			
		}
		
		/**
		 * 初期処理
		 * @param	e
		 */
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			
			//リボンの振りとうねりの開始角度を決定
			rad1 = Math.floor(Math.random() * 36) * 10;
			rad2 = Math.floor(Math.random() * 36) * 10;
			drad1 = 3;

			//ダミースプライト生成
			var i1:Number = MAXNUMBER;
			Sprites = new Array();
			while (i1--) {
               Sprites.push({x:offsetX, y:((stage.stageHeight+30) /MAXNUMBER) *i1+offsetY - 15});
			}
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
			// entry point
		}

		/**
		 * ループ処理
		 * @param	e
		 */
		private function onEnterFrame(e:Event):void 
		{
			headTrail();
			trail(0,MAXNUMBER, 0.9);
			drawPolygon();
		}
		
		
		/**
		 * 最初のスプライトの動き
		 */
		private function headTrail():void
		{
			rad1 += drad1;
			rad2 += 2;
			if(rad1 >360){
				rad1 = rad1 - 360;
				drad1 = Math.random()*4+2;//目標周期をランダムに決定(2~6)
			}
			if(rad2 >360){
				rad2 = rad2 - 360;
			}
			Sprites[0].x = Math.sin(rollDirection*rad1 * Math.PI/180)*widthPiece+offsetX;
		}
		/**
		 * 先頭の点以外の処理
		 * @param	st
		 * @param	end
		 * @param	rate
		 */
		private function trail(st:int,end:int,rate:Number):void
		{
			for (var i:int = (end - 1); i > st; i-- ) {
				Sprites[i].x = Sprites[(i - 1)].x;
			}
		}
		
		/**
		 * ポリゴンの描写
		 */
		private function drawPolygon():void
		{
			
			var i1:int = MAXNUMBER;
			graphics.clear();
			while (--i1) {
				graphics.beginFill(color);
				graphics.lineStyle(0, color, 1);
				var w1:Number = WIDTH*Math.cos(rollDirection*(rad2+i1*2+45) * Math.PI/180)/2;
				graphics.moveTo(Sprites[i1].x-w1, Sprites[i1].y-w1);
				graphics.lineTo(Sprites[i1].x + w1, Sprites[i1].y + w1);
				
				var w2:Number = WIDTH*Math.cos(rollDirection*(rad2+i1*2+45) * Math.PI/180)/2;
				graphics.lineTo(Sprites[(i1-1)].x+w2, Sprites[(i1-1)].y+w2);
				graphics.lineTo(Sprites[(i1-1)].x-w2, Sprites[(i1-1)].y-w2);
				graphics.lineTo(Sprites[i1].x-w1, Sprites[i1].y-w1);
				graphics.endFill();
			}			
		}
	}