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

うねうねさせたい

小さくうねったり大きくうねったりランダムな感じ(かつ自然な感じ)にしたい。
一定すぎてつまらん。
Get Adobe Flash player
by fumix 01 Jun 2009
    Embed
/**
 * Copyright fumix ( http://wonderfl.net/user/fumix )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/2ySR
 */

//小さくうねったり大きくうねったりランダムな感じ(かつ自然な感じ)にしたい。
//一定すぎてつまらん。
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 
	{
		private const MAXNUMBER:int = 60;
		private var widthPiece:Number;
		private var rad1:Number;
		private var rad2:Number;
		private var lossRateAll: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);
		}
		
		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;
			widthPiece = 20;
			lossRateAll = 0.9;
			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 = offsetX;
				ball.x = Math.sin((rad1+i1*10) * Math.PI/180)*widthPiece+offsetX;

				//addChild(ball);
                Sprites.push(ball);
			}
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
			// entry point
		}
		
		private function onEnterFrame(e:Event):void 
		{
			trail(0,MAXNUMBER, 0.9);
			drawPolygon();
		}
		
		
		/**
		 * うねうね処理
		 * @param	st
		 * @param	end
		 * @param	rate
		 */
		private function trail(st:int,end:int,rate:Number):void
		{
			rad1 += 1;
			rad2 += 2;
			lossRateAll *= 0.5;
			for (var i:int = st; i < end; i++ ) {
				Sprites[i].x = Math.sin((rad1+(i+1)*10) * Math.PI/180)*widthPiece+offsetX;
			}		
		}
		
		/**
		 * ポリゴンの描写
		 */
		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*3+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*3+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();
    }
}