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: forked from: [QuickBox2D] Doll in space_2

Get Adobe Flash player
by figma000 23 May 2012
    Embed
/**
 * Copyright figma000 ( http://wonderfl.net/user/figma000 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/7LmV
 */

// forked from aduonety's forked from: forked from: [QuickBox2D] Doll in space_2
// forked from a24's forked from: [QuickBox2D] Doll in space
// forked from paq's [QuickBox2D] Doll in space

package 
{
    import Box2D.Common.Math.b2Vec2;
    import Box2D.Dynamics.b2Body;
    import com.actionsnippet.qbox.objects.CircleObject;
    import com.actionsnippet.qbox.QuickBox2D;
    import com.actionsnippet.qbox.QuickObject;
    import flash.display.MovieClip;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    import flash.geom.Rectangle;
    import flash.events.MouseEvent;
    
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import frocessing.math.*;
    import jp.progression.commands.lists.*;
    import jp.progression.commands.*;
    import com.bit101.components.*;

    
   [SWF(width = 465, height = 465, backgroundColor = 0x333333, frameRate = 60)]
    
    public class Sample extends MovieClip
    {
        private var sim:QuickBox2D;
        private var fixedPoint:b2Vec2 = new b2Vec2(7.25, 7.25);
        private var scale:Number = 10;
        private var balls:Array = new Array();
        
        public function Sample():void 
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }
        
        private function init(e:Event = null):void 
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);
            stage.scaleMode = StageScaleMode.NO_SCALE;
            
            sim = new QuickBox2D(this);
            sim.gravity = new b2Vec2(0, 30);
            sim.iterations = 10;
        // sim.createStageWalls();
            
            sim.setDefault( { fillColor:0xFFFFFF, lineColor:0x333333 } );
            
            for (var i:int = 0; i < 10; i++)  //玉の生成
            {
                balls.push(sim.addCircle( { x:Math.random() * 15.5, y:Math.random() * 7, radius:0.3 } ));
            }

              {
//////////////////////////////////////////////////////////////////////////////////////////////////////
                
        private var panel:Panel
        private var bd:BitmapData;
        private var destbd:BitmapData;
        private var bitmap:Bitmap;
        private var list:SerialList = new SerialList();
        private var wait:Number = 10 / 1000.0;
        
        public function Main()
        {
            Wonderfl.capture_delay(10);
            
            panel = new Panel(this);
            panel.width = panel.height = 465;
            
            stage.frameRate = 120;
            bd = new BitmapData(100, 100, false, Status.FIELD);
            
            destbd = bd.clone();
            
            bitmap = new Bitmap(destbd);
            bitmap.scaleX = bitmap.scaleY = 6;
            bitmap.x = (465 - bitmap.width) / 2;
            panel.content.addChild(bitmap);
            dig2()
        }
        
        private function sliderHandler(event:Event):void
        {
            var slider:HUISlider = event.currentTarget as HUISlider;
            wait = slider.value / 1000.0;
        }
        
        private function dig2(event:Event = null):void
        {
            list.clearCommand(true);
            list = new SerialList();
            bd = new BitmapData(100, 100, false, Status.FIELD);
            
            destbd = bd.clone();
            bitmap.bitmapData = destbd;
       
            for (var y:int = 0; y < bd.height; y++)
            {
                for (var x:int = 0; x < bd.width; x++)
                {//外壁と柱づくり
                    if (y == 0 || x == 0 || y == bd.height - 1 || x == bd.width - 1 || y % 2 == 0 && x % 2 == 0)//外かべづくり
                    {
                        bd.setPixel(x, y, Status.WALL);
                        list.addCommand(new Func(function(x:int, y:int):void { destbd.setPixel(x, y, Status.WALL); }, [x, y]));
                        list.addCommand(new Wait(wait));
                    }
                }
            }
            for (y = 2; y < bd.height - 1; y += 2)
            {
                var dx:int = 2;
                var dy:int = y;
                
                switch (int(Math.random() * 4))
                {
                    case 0: dx++; break;
                    case 1: dx--; break;
                    case 2: dy++; break;
                    case 3: dy--; break;
                }
                if (bd.getPixel(dx, dy) != Status.WALL)
                {
                    bd.setPixel(dx, dy, Status.WALL);
                    list.addCommand(new Func(function(x:int, y:int):void { destbd.setPixel(x, y, Status.WALL); }, [dx, dy]));
                    list.addCommand(new Wait(wait));
                }
                else y -= 2;
            }
            for (x = 4; x < bd.width - 1; x += 2)
            {
                for (y = 2; y < bd.height - 1; y += 2)
                {
                    dx = x;
                    dy = y;    
                    switch (int(Math.random() * 3))
                    {
                        case 0: dy++; break;
                        case 1: dy--; break;
                        case 2: dx++; break;
                    }
                    if (bd.getPixel(dx, dy) != Status.WALL)
                    {
                        bd.setPixel(dx, dy, Status.WALL);
                        list.addCommand(new Func(function(x:int, y:int):void { destbd.setPixel(x, y, Status.WALL); }, [dx, dy]));
                        list.addCommand(new Wait(wait));
                    }
                    else y -= 2;
                }
            }
            list.execute();
        }
    }
}
class Status
{
    public static const FIELD:int = 0xF3F3F3;
    public static const WALL:int = 0x393939;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
              }
              
            sim.start();
            sim.mouseDrag();
        }

        
        private function loop(e:Event):void 
        {
            for ( var i:int = 0; i < balls.length; i ++ )
            {
                var ball:QuickObject = balls[i];
                var fp:b2Vec2 = fixedPoint.Copy();
                fp.Subtract(ball.body.GetPosition());
                fp.Normalize();
                fp.Multiply(50);
                balls.push(sim.addCircle( { x:Math.random() * 15.5, y:Math.random() * 7, radius:0.6 } ));
                ball.body.ApplyForce(fp, ball.body.GetWorldCenter());
                ball.body.ApplyForce(new b2Vec2(0, -30), ball.body.GetWorldCenter());
            }
        }
    }
}