flash on 2010-10-8

by plus-tic
♥0 | Line 47 | Modified 2010-10-08 11:30:41 | MIT License
play

ActionScript3 source code

/**
 * Copyright plus-tic ( http://wonderfl.net/user/plus-tic )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/1fB2
 */

package {
    import flash.display.Sprite;
    import flash.events.Event;
    
    public class IK extends Sprite {
        private var seg0:Segment;
        
        public function IK() {
            init();            
        }
        
        private function init():void{
            seg0 = new Segment(100, 20);
            addChild(seg0);
            seg0.x = stage.stageWidth/2;
            seg0.y = stage.stageHeight/2;
        }
    }
}

import flash.geom.Point;
import flash.display.Sprite;

class Segment extends Sprite{
    private var color:uint;
    private var segmentWidth:Number;
    private var segmentHeight:Number;
    
    public var vx:Number = 0;
    public var vy:Number = 0;
    
    public function Segment(segmentWidth:Number,segmentHeight:Number,color:uint = 0xffffff){
        this.segmentWidth = segmentWidth;
        this.segmentHeight = segmentHeight;
        this.color = color;
        init();
    }
    
    public function init():void{
        graphics.lineStyle(0);
        graphics.beginFill(color);
        graphics.drawRoundRect( -segmentHeight / 2, -segmentHeight / 2, segmentWidth+segmentHeight, segmentHeight, segmentHeight, segmentHeight );
        graphics.endFill();
        
        graphics.drawCircle(0,0,2);
        graphics.lineStyle(0,0x6f6cff);
        graphics.beginFill(0x6f6cff);
        graphics.drawCircle(segmentWidth,0,2);
    }
    
    public function getPin():Point{
        var angle:Number = rotation * Math.PI/180;
        var xPos:Number = x + Math.cos( angle ) * segmentWidth;
        var yPos:Number = y + Math.sin( angle ) * segmentWidth;
        return new Point(xPos,yPos);
    }
}