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

Get Adobe Flash player
by hacker_3szp8277 23 Dec 2008
package  {
    import flash.display.*;
    import flash.events.Event;
    
    [SWF(width="500", height="500", backgroundColor="0xeeffee", frameRate="24")]  
	public class RoboArm extends Sprite {
		private var screen:Sprite;
		private var arms:Array = new Array;
		private var ball:Ball;
		public function RoboArm() {
			this.screen = this;
			var i:int;
			ball = new Ball();
			ball.x = Math.random()*400;
			ball.y = Math.random()*400;
			addChild(ball);
			for( i =0;i<30;i++)
			arms.push(new Arm(this,ball,Math.random()*400+50,Math.random()*400+50));

			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, 0xff00,0.2);
		    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 = 0xff0000;
        effector1 = new Sprite();
        effector2 = new Sprite();
        g = effector1.graphics;
        g.lineStyle(1, handColor,0.5);
        g.drawRect(-5, -5, 30, 10);
        g.drawRect(20, -10, 5, 15);
        g.drawCircle(0, 0, 8);
        g = effector2.graphics;
        g.lineStyle(1, handColor,0.5);
        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=50;
	public function Ball(){
		graphics.beginFill(0xccffcc);
		graphics.drawCircle(0,0,10);
                  graphics.beginFill(0xaa);
                    graphics.drawCircle(0,0,5);
                    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>450||x<0)vx*=-1;
		if(y>450||y<0)vy*=-1;
	}
}