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

不規則な円をゆっくりとアニメーションさせる(複数動かす)

/**
 * Copyright _wonder ( http://wonderfl.net/user/_wonder )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/xFnL
 */

// forked from _wonder's 不規則な円をゆっくりとアニメーションさせる
// forked from _wonder's 不規則な円
// forked from _wonder's curveToを使って閉じた曲線を描く
package {
    import flash.display.Sprite;
    import flash.events.Event;

    public class Moveball extends Sprite {
        private var ball:Ball;
        
        public function Moveball() {
            init();
        }
        
        public function init():void {
        		for( var i:int = 0; i < 3; i++ ){
        			var ball:Ball = new Ball( 0x32280c );
        			ball.x = stage.stageWidth / 2 + (Math.random()*5-5);
        			ball.y = stage.stageHeight / 2 + (Math.random()*5-5);
        			ball.alpha = 0.5;
        			addChild( ball );
        		}
        }
    }
}


import flash.display.Sprite;
import flash.events.Event;

class Ball extends Sprite {
        private var num:uint = 14;
        private var radius:Number = 100;
        private var rdm:Number = 15;
        private var points:Array = [];
        private var nextpoints:Array = [];
        private var per:Number = 0.3;
        private var color:uint;
        
        public function Ball( color:uint ) {
        		this.color = color;
        		init();
        }
        
        private function init():void {
        		points = getPoint();
        		nextpoints = getPoint();
        		
        		addEventListener(Event.ENTER_FRAME, onEnterFrame);
        }
        
        private function onEnterFrame(e:Event):void {
        		for( var i:int = 0; i < points.length; i++){
        			(points[i].x - nextpoints[i].x) > 0 ? points[i].x -= per : points[i].x += per ;
        			(points[i].y - nextpoints[i].y) > 0 ? points[i].y -= per : points[i].y += per ;
        		}
        		if( Math.abs(points[0].x - nextpoints[0].x) < per ){ nextpoints = getPoint(); };
        		
        		createBall( points );
        }
        
        private function createBall( _points:Array ):void {
        		graphics.clear();
        		
        		graphics.lineStyle(1, color);
        	    graphics.beginFill(color);
        		
        		var xc1:Number = (_points[0].x+_points[num-1].x) / 2;
        		var yc1:Number = (_points[0].y+_points[num-1].y) / 2;
        		graphics.moveTo(xc1,yc1);
        		
        		for(var j:int = 0; j < num-1; j++){
        			var xc:Number = (_points[j].x+_points[j+1].x) / 2;
        			var yc:Number = (_points[j].y+_points[j+1].y) / 2;
        			graphics.curveTo(_points[j].x, _points[j].y, xc, yc);
        		}
        		
        		graphics.curveTo(points[j].x, points[j].y, xc1, yc1);
        }
        
        private function getPoint():Array {
        		var array:Array = [];
        		for( var i:int = 0; i < num; i++){
            		var rad:Number = (i*360/num) * Math.PI / 180;
            		array[i] = new Object();
            		array[i].x = Math.sin( rad ) * radius + (Math.random() * rdm);
            		array[i].y = Math.cos( rad ) * radius + (Math.random() * rdm);
            }
            return array;
        }
    }