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: うねうねさせたい2

小さくうねったり大きくうねったりランダムな感じ(かつ自然な感じ)にしたい。
ロジックを変えて一応ランダムなうねうねにした・・・けどイマイチ
一定周期毎の変化じゃなくだんだん周期が変化する感じにしたい。
Get Adobe Flash player
by hacker_ehiz4io1 19 Aug 2009
    Embed
/**
 * Copyright hacker_ehiz4io1 ( http://wonderfl.net/user/hacker_ehiz4io1 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/nL8Q
 */

// forked from mushi_cake's forked from: うねうねさせたい2
// forked from fumix's うねうねさせたい2
//小さくうねったり大きくうねったりランダムな感じ(かつ自然な感じ)にしたい。
//ロジックを変えて一応ランダムなうねうねにした・・・けどイマイチ
//一定周期毎の変化じゃなくだんだん周期が変化する感じにしたい。
package 
{
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.Event;
	
	/**
	 * ...
	 * @author DefaultUser (Tools -> Custom Arguments...)
	 */
    [SWF(width = "465", height = "700", frameRate = "30", backgroundColor = "#ffffff")]
	public class Main extends Sprite 
	{
		private const MAXNUMBER:int = 100;
		
		private var widthPiece:Number;
		
		private var rad1:Number;
		private var rad2:Number;
		private var drad1:Number;
		
		private var Sprites:Array;
		
		private var offsetX:Number;
		private var offsetY:Number;
		
		
		
		
		/**
		 * コンストラクタ
		 */
		public function Main():void 
		{
			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;
			drad1 = 5;
			rad2 = Math.floor(Math.random() * 36) * 10;
			//リボンの振り幅
			widthPiece = 15;
			//オフセット値
			offsetX = stage.stageWidth / 2;
			offsetY = 0;
			//ダミースプライト生成
			var i1:Number = MAXNUMBER;
			Sprites = new Array();
			while (i1--) {
				var ball:Ball = new Ball(7, 0xff0000, 1);
				ball.y = (stage.stageHeight /MAXNUMBER) *i1+offsetY;
				//ball.x = Math.sin((rad1+i1*10) * Math.PI/180)*widthPiece+offsetX;

				//addChild(ball);
                Sprites.push(ball);
			}
			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;
				if (Math.floor(Math.random() * 3) < 1) {
					drad1 = Math.random()*4+2;//目標周期をランダムに決定(0~3.99999)
				}
			}
			if(rad2 >360){
				rad2 = rad2 - 360;
			}
			//var xsp = (this._xmouse-posx)*0.03+1;
			//var ysp = (this._ymouse-posy)*0.03+1;
			//posx += xsp;
			//posy += ysp;
			var firstBall:Ball = Sprites[0];
			firstBall.x = Math.sin(rad1 * Math.PI/180)*widthPiece+offsetX;
			//this.p0._x += xsp*2;
			//this.movy(ysp);
			
		}
		/**
		 * 先頭の点以外の処理
		 * @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-- ) {
				//trace(i);
				//Sprites[i].x = Math.sin((rad1+(i+1)*10) * Math.PI/180)*widthPiece+offsetX;
				Sprites[i].x = Sprites[(i - 1)].x;
				//setTrail(Sprites[i1], Sprites[(i1-1)], rate);
			}
		}
		
		/**
		 * 先頭の点以外の処理(一個当たりの処理)
		 * @param	targetMc
		 * @param	currentMc
		 * @param	rate
		 */
		private function setTrail(targetMc:Ball,currentMc:Ball,rate:Number):void
		{
			//var spx:Number = (currentMc.x - targetMc.x) * rate * lossRateAll;
			//targetMc.x += spx;
		}
		/**
		 * ポリゴンの描写
		 */
		private function drawPolygon():void
		{
			
			var i1:int = MAXNUMBER;
			graphics.clear();
			while (--i1) {
				graphics.beginFill(0xFFFFFF);
				graphics.lineStyle(0, 0x000000, 100);
				var p0:Ball = Sprites[i1];
				var w1:Number = p0.width*Math.cos((rad2+i1*2+45) * Math.PI/180)/2;
				graphics.moveTo(p0.x-w1, p0.y-w1);
				graphics.lineTo(p0.x+w1, p0.y+w1);
				var p1:Ball = Sprites[(i1-1)];
				var w2:Number = p1.width*Math.cos((rad2+i1*2+45) * Math.PI/180)/2;
				graphics.lineTo(p1.x+w2, p1.y+w2);
				graphics.lineTo(p1.x-w2, p1.y-w2);
				graphics.lineTo(p0.x-w1, p0.y-w1);
				graphics.endFill();
			}			
		}
	}
	
}

import flash.display.Sprite;
    
class Ball extends Sprite
{
    public var radius:Number;
    public var color:uint;
    public var vx:Number = 0;
    public var vy:Number = 0;
    public var mass:Number = 0;
    public function Ball(radius:Number, color:uint, alpha:Number)
    {
        this.radius = radius;
        this.color = color;
        this.alpha = alpha;
        init();
    }
    
    public function init():void
    {
        graphics.beginFill(color);
        graphics.drawCircle(0, 0, radius);
        graphics.endFill();
    }
}