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 kuma360 30 Oct 2010
    Embed
/**
 * Copyright kuma360 ( http://wonderfl.net/user/kuma360 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/9E1U
 */

package 
{
    import flash.display.*;
    import flash.events.*;
    import flash.filters.*;
    import flash.geom.*;
    import flash.utils.*;
    
    //ローレンツ方程式
    //ルンゲクッタ法
    //適当にまわしてみた
    
    public class Main extends Sprite 
    {
        /////////////////////////////////
        private var screen:BitmapData = new BitmapData ( 465 , 465 , false , 0 ) ;
        public function Main():void {
            addChild ( new Bitmap ( screen ) ) ;
            addEventListener ( Event.ENTER_FRAME , run ) ;
        }
        
        /////////////////////////////////
        private var X:Number = .1 ;
        private var Y:Number = .1 ;
        private var Z:Number = .1 ;
        private function run ( e:Event ) :void {
            
            var V:Vector3D = new Vector3D ;
            var M:Matrix3D = new Matrix3D ;
            
            var p:Number = 10 ;
            var r:Number = 28 ;
            var b:Number = 8 / 3 ;
            
            var K1:Number = 0 ;
            var K2:Number = 0 ;
            var K3:Number = 0 ;
            var K4:Number = 0 ;
            
            var step:Number = .0001 ;
            
            screen.applyFilter ( screen , screen.rect , new Point , new BlurFilter ) ;
            
            var S:uint = getTimer () ;
            while ( getTimer() - S < 10 ) {
                
                K1 = step * ( ( - p * ( X )          ) + ( p * ( Y )          ) ) ;
                K2 = step * ( ( - p * ( X + K1 / 2 ) ) + ( p * ( Y + K1 / 2 ) ) ) ;
                K3 = step * ( ( - p * ( X + K2 / 2 ) ) + ( p * ( Y + K2 / 2 ) ) ) ;
                K4 = step * ( ( - p * ( X + K3 )     ) + ( p * ( Y + K3 )     ) ) ;
                var NX:Number = X + ( K1 + 2 * K2 + 2 * K3 + K4 ) / 6 ;
                
                K1 = step * ( ( - ( X )          * ( Z )          ) + ( r * ( X )          ) - ( Y )          ) ;
                K2 = step * ( ( - ( X + K1 / 2 ) * ( Z + K1 / 2 ) ) + ( r * ( X + K1 / 2 ) ) - ( Y + K1 / 2 ) ) ;
                K3 = step * ( ( - ( X + K2 / 2 ) * ( Z + K2 / 2 ) ) + ( r * ( X + K2 / 2 ) ) - ( Y + K2 / 2 ) ) ;
                K4 = step * ( ( - ( X + K3 )     * ( Z + K3 )     ) + ( r * ( X + K3     ) ) - ( Y + K3     ) ) ;
                var NY:Number = Y + ( K1 + 2 * K2 + 2 * K3 + K4 ) / 6 ;
                
                K1 = step * ( ( ( X )          * ( Y )          ) - ( b * ( Z )          ) ) ;
                K2 = step * ( ( ( X + K1 / 2 ) * ( Y + K1 / 2 ) ) - ( b * ( Z + K1 / 2 ) ) ) ;
                K3 = step * ( ( ( X + K2 / 2 ) * ( Y + K2 / 2 ) ) - ( b * ( Z + K2 / 2 ) ) ) ;
                K4 = step * ( ( ( X + K3 )     * ( Y + K3 )     ) - ( b * ( Z + K3 )     ) ) ;
                var NZ:Number = Z + ( K1 + 2 * K2 + 2 * K3 + K4 ) / 6 ;
                
                X = NX ;
                Y = NY ;
                Z = NZ ;
                
                M.identity () ;
                M.appendRotation ( S * .03 , Vector3D.X_AXIS ) ;
                M.appendRotation ( S * .01 , Vector3D.Y_AXIS ) ;
                M.appendRotation ( S * .02 , Vector3D.Z_AXIS ) ;
                V = M.transformVector ( new Vector3D ( X , Y , Z ) ) ;
                
                screen.setPixel ( V.x * 5 + 200 , V.y * 5 + 200 , 0xFFFFFF ) ;
                
            }
            
        }
        
    }
    
}