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 undo's 周波数の違う振り子を一斉にスタート
package
{
    
    import flash.display.*;
    import flash.events.Event;

    [SWF(width=465,height=465,backgroundColor=0x000000,frameRate=60)]
    public class ASTest extends Sprite
    {
        
        private const AMPLITUDE:Number = 40;
        private const MIN_LENGTH:Number = 100;
        private const LENGTH_INTERVAL:Number = 20;
        private const NUM_PENDULUMS:int = 10;
        
        private var _array:Array;
        
        public function ASTest()
        {
            this.addEventListener(Event.ADDED_TO_STAGE, init);
        }
        private function init(evt:Event = null):void
        {
            _array = new Array();
            for(var i:int = NUM_PENDULUMS-1; i > -1; i--)
            {
                var cr:uint,cg:uint,cb:uint;
                cr=(uint)((Math.sin(i*360/NUM_PENDULUMS*Math.PI/180)+1)/2*255);
                cg=(uint)((Math.sin((i*360/NUM_PENDULUMS+120)*Math.PI/180)+1)/2*255);
                cb=(uint)((Math.sin((i*360/NUM_PENDULUMS-120)*Math.PI/180)+1)/2*255);
                var pendulum:Pendulum = new Pendulum(AMPLITUDE, Math.sqrt(LENGTH_INTERVAL*LENGTH_INTERVAL*i+MIN_LENGTH*MIN_LENGTH), cr*256*256+cg*256+cb);
                addChild(pendulum);
                pendulum.x = Math.floor(stage.stageWidth/2);
                pendulum.y = 160+LENGTH_INTERVAL*i-Math.sqrt(LENGTH_INTERVAL*LENGTH_INTERVAL*i+MIN_LENGTH*MIN_LENGTH);
                
                //pendulum.start();
                _array.push(pendulum);
            }
            
            addEventListener(Event.ENTER_FRAME, onEnter);
        }
        
        private function onEnter(evt:Event):void
        {
            for(var i:int = 0; i < _array.length; i++)
            {
                var p:Pendulum = _array[i] as Pendulum;
                p.onEnter();
            }
        }
    }
}

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

class Pendulum extends Sprite
{
    
    private var _amp:Number;
    private var _length:Number;
    private var _color:uint;
    
    private var _radian:Number = 0;
    private var _omega:Number = 0;
    
    private const DEF_LENGTH:Number = 10;
    private const DEF_OMEGA:Number = 0.4;
    private const RADIUS:Number = 10;
    
    public function Pendulum(amplitude:Number = 20, length:Number = 300, color:uint = 0xffffff)
    {
        _amp = amplitude;
        _length = length;
        _color = color;
        _omega =  Math.sqrt(DEF_LENGTH/_length)*DEF_OMEGA;//たぶん
        init();
    }
    private function init():void
    {
        this.graphics.clear();
        this.graphics.beginFill(_color);
        this.graphics.drawCircle(0,_length, RADIUS);
        this.graphics.endFill();
        this.graphics.lineStyle(1,_color);
        this.graphics.moveTo(0,0);
        this.graphics.lineTo(0,_length);
    }
    
    public function start():void
    {
        addEventListener(Event.ENTER_FRAME, onEnter);
    }
    public function onEnter(evt:Event = null):void
    {
        _radian += _omega;
        var newX:Number = Math.sin(_radian)*_amp;
        var newY:Number = Math.sqrt(_length*_length - newX*newX);
        this.graphics.clear();
        this.graphics.beginFill(_color);
        this.graphics.drawCircle(newX,newY, RADIUS);
        this.graphics.endFill();
        this.graphics.lineStyle(1,_color);
        this.graphics.moveTo(0,0);
        this.graphics.lineTo(newX,newY);
        
    }
}