forked from: Open Jpg Image WithOut PHP(FP10)

by Akiyah forked from Open Jpg Image WithOut PHP(FP10) (diff: 106)
♥0 | Line 89 | Modified 2010-10-09 18:17:16 | MIT License
play

ActionScript3 source code

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

<?xml version="1.0" encoding="utf-8"?>
<!-- forked from heart_thai's Open Jpg Image WithOut PHP(FP10) -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
    <mx:Script>
        <![CDATA[
package {
    import flash.display.Sprite;
    import flash.display.*;
    import flash.events.Event;
    import flash.events.MouseEvent;
    
    [SWF(width="420",height="420",frameRate="10", backgroundColor="#000000")]
    public class LineMan extends Sprite {
        private const LINE_WIDTH:int = 4;
        private const LAYER_SIZE:int = 4;

        private var count:int = 0;
        private var number:int = 2;
        private var linesShapes:Array = [];
        private var men:Shape = new Shape();

        public function LineMan() {
            for (var i:int = 0; i < LAYER_SIZE; i++) {
                linesShapes[i] = new Shape();
            }
            drawLineMan();

            stage.addEventListener(Event.ENTER_FRAME, atEveryFrame);
            stage.addEventListener(MouseEvent.CLICK, changeNumber);
        }

        private function changeNumber(e:MouseEvent):void {
            number += 1;
            drawLineMan();
            for (var i:int = 0; i < LAYER_SIZE; i++) {
                linesShapes[i].graphics.clear();
            }
        }

        private function drawLineMan():void {
            men.graphics.clear();
            men.graphics.beginFill(0x000000, 0);
            men.graphics.lineStyle(LINE_WIDTH, 0xFFFFFF);
            for (var j:int = 0; j < number; j++) {
                var x:int = get_x(j);
                var y:int = get_y(j);

                men.graphics.drawCircle(x, y, LINE_WIDTH * 2);

                men.graphics.moveTo(x, y + LINE_WIDTH * 2);
                men.graphics.lineTo(x, y + LINE_WIDTH * 2 + LINE_WIDTH * 3);

                men.graphics.moveTo(x - LINE_WIDTH * 3, y + LINE_WIDTH * 3);
                men.graphics.lineTo(x + LINE_WIDTH * 3, y + LINE_WIDTH * 3);

                men.graphics.moveTo(x, y + LINE_WIDTH * 5);
                men.graphics.lineTo(x + LINE_WIDTH * 2, y + LINE_WIDTH * 8);

                men.graphics.moveTo(x, y + LINE_WIDTH * 5);
                men.graphics.lineTo(x - LINE_WIDTH * 2, y + LINE_WIDTH * 8);
            }
            men.graphics.endFill();
        }

        private function atEveryFrame(e:Event):void {
            var s:Shape = linesShapes[count % LAYER_SIZE];
            s.graphics.clear();
            s.graphics.beginFill(0x000000, 0);
            s.graphics.lineStyle(LINE_WIDTH, 0x00FF00);
            for (var i:int = 0; i < number; i++) {
                var i1:int = get_target(i);
                s.graphics.moveTo(get_x(i), get_y(i));
                s.graphics.lineTo(get_x(i1), get_y(i1));
            }
            s.graphics.endFill();

            for (i = 0; i < LAYER_SIZE; i++) {
                linesShapes[i].alpha *= 0.5;
            }
            s.alpha = 1;

            addChild(s);
            addChild(men);

            count += 1;
        }

        private function get_x(i:int):int {
            var c:Number = 2 * Math.PI * i / number;
            return (1 + Math.cos(c)) * stage.stageWidth / 2 + 5;
        }

        private function get_y(i:int):int {
            var c:Number = 2 * Math.PI * i / number;
            return (1 + Math.sin(c)) * stage.stageWidth / 2 + 5;
        }

        private function get_target(i:int):int {
            var j:int = Math.floor(Math.random() * (number - 1));
            return (i <= j) ? j + 1 : j;
        }
    }
}

        ]]>
    </mx:Script>
    
    <mx:Button label="Click" click="openFile()"></mx:Button>
</mx:Application>