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: Robot Arm

// forked from hacker_3szp8277's forked from: forked from: Robot Arm
// forked from hacker_3szp8277's forked from: Robot Arm
package  {
    import flash.display.*;
    import flash.events.Event;
    import flash.geom.Point;
        
    [SWF(width="800", height="800", backgroundColor="0x000000", frameRate="25")]  
    public class RoboArm2 extends Sprite {
            
         
        private var screen:Sprite;
        private var arms:Array = new Array;
        private var ball:Ball;
        public function RoboArm2() {
             var bg_color:Number = 0x000000; 
        var background:Sprite = new Sprite(); 
           background.graphics.beginFill(bg_color); 
             background.graphics.drawRect(0, 0, 800, 800); 
                    addChild(background); 
            this.screen = this;
            var i:int;
            ball = new Ball();
            ball.x = Math.random()*400;
            ball.y = Math.random()*400;
            addChild(ball);
            var center:Point = new Point(800/2,800/2);
            const count:int = 30;
            var length:Number = 150;
            for( i =0;i<count;i++){
                                var rad:Number = Math.PI/count*i*2;
                var x:Number = center.x+Math.cos(rad)*length;
                var y:Number = center.y+Math.sin(rad)*length;
                                arms.push(new Arm(this,ball,x,y));
                //length +=5;
            }

            addEventListener(Event.ENTER_FRAME, onEnterFrame);
        }

        public function onEnterFrame(ev:Event):void {
            draw();
            ball.Update();
        }

         
        public function draw():void {
            for(var i:int =0;i<arms.length;i++){
                arms[i].Draw();
            }
        }
    }
}
import flash.display.Sprite;
import flash.geom.Point;
import flash.display.Graphics;    

class Arm{
    private const NARM:int = 4;
    private const LENGTH:Number = 58;
    private var angles:Array;
    private var arms:Array;
    private var effector1:Sprite;
    private var effector2:Sprite;
    private var screen:Sprite;
    private var ball:Ball;
    private var posX:int;
    private var posY:int;
    
    public function Arm(screen:Sprite,ball:Ball,posX:int,posY:int){
        this.posX = posX;
        this.posY = posY;
        var g:Graphics;
        angles = new Array();
        arms = new Array();
        this.screen = screen;
        this.ball = ball;
        var i:int;
        for (i = 0; i < NARM; i++) {
            angles[i] = 0.0;
            arms[i] = new Sprite();
            g = arms[i].graphics;
            g.lineStyle(1, 0xffffff,1);
            g.drawRoundRect(-8, -8, LENGTH + 16, 16, 16);
            g.drawCircle(0, 0, 3);
            g.drawCircle(0, 0, 8);
            screen.addChild(arms[i]);
        }
        var handColor:uint = 0xff4f00;
        effector1 = new Sprite();
        effector2 = new Sprite();
        g = effector1.graphics;
        g.lineStyle(1, handColor,1);
        g.drawRect(-5, -5, 30, 10);
        g.drawRect(20, -10, 5, 15);
        g.drawCircle(0, 0, 8);
        g = effector2.graphics;
        g.lineStyle(1, handColor,1);
        g.drawRect(-5, -5, 30, 10);
        g.drawRect(20, -5, 5, 15);
        g.drawCircle(0, 0, 3);
        screen.addChild(effector1);
        screen.addChild(effector2);
    }
    public function pursuit(bi:uint, o:Point, p:Point):Point {
        var e:Point;
        if (bi < NARM - 1) {
            const o2:Point = new Point(
                    o.x + Math.cos(angles[bi]) * LENGTH,
                    o.y + Math.sin(angles[bi]) * LENGTH);
            e = pursuit(bi + 1, o2, p);
        } else {
            e = new Point(
                    o.x + Math.cos(angles[bi]) * (LENGTH + 20),
                    o.y + Math.sin(angles[bi]) * (LENGTH + 20));
        }

        if ((e.y == o.y && e.x == o.x) || (p.y == o.y && p.x == o.x))
            return e;

        const anglee:Number = Math.atan2(e.y - o.y, e.x - o.x);
        const anglep:Number = Math.atan2(p.y - o.y, p.x - o.x);
        var angle_d:Number = (anglep - anglee);

        if (angle_d > Math.PI) angle_d = angle_d - 2 * Math.PI;
        else if (angle_d < -Math.PI) angle_d = angle_d + 2 * Math.PI;    
        if (angle_d > 0.025) angle_d = 0.025;
        else if (angle_d < -0.025) angle_d = -0.025;
        angles[bi] += angle_d;

        return e;
    }
    private var ph:Number = 0;
    public function Draw():void{
         var i:int;
        var x:Number;
        var y:Number;

        var e:Point;
        for (i = 0; i < 10; i++)
            e = pursuit(0, new Point(posX, posY), new Point(ball.x,ball.y));

        x = posX;
        y = posY;
        for (i = 0; i < NARM; i++) {
            arms[i].x = x;
            arms[i].y = y;
            arms[i].rotation = angles[i] / Math.PI * 180;
            x += LENGTH * Math.cos(angles[i]);
            y += LENGTH * Math.sin(angles[i]);
        }

        var dx:Number = e.x - screen.mouseX;
        var dy:Number = e.y - screen.mouseY;
        if (dx * dx + dy * dy < 50)
            ph += 0.1;
        var angle_e:Number = arms[NARM - 1].rotation;
        var angle_ed:Number = 25 + 30 * Math.pow(Math.sin(ph), 2);
        effector1.x = effector2.x = e.x - Math.cos(angles[NARM - 1]) * 25;
        effector1.y = effector2.y = e.y - Math.sin(angles[NARM - 1]) * 25;
        effector1.rotation = angle_e + angle_ed;
        effector2.rotation = angle_e - angle_ed;
    }

}

class Ball extends Sprite{
    private var vx:Number
    private var vy:Number;
    private var spd:Number=30;
    public function Ball(){
        graphics.beginFill(0xccffcc);
        graphics.drawCircle(0,0,0);
                  graphics.beginFill(0xaa);
                    graphics.drawCircle(0,0,0);
                    var rad:Number = Math.random()*Math.PI
        vx=Math.cos(rad)*spd;
        vy=Math.sin(rad)*spd;
            alpha=0.5;
    }
    public function Update():void{
        x += vx;
        y += vy;
        if(x>620||x<0)vx*=-1;
        if(y>620||y<0)vy*=-1; 
    }
}