재미로하는 10년간의 행운그래프 입니다.

운이 별로 좋지 않게 나오면 노력으로 메꾸세요.


사용방법 : 태어난 년도와 이름을 적고 확인버튼을 누르세요.

마우스 오른쪽 버튼으로 언어전환을 할 수 있습니다. (fp11.2)









코드
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package
{
    import adobe.utils.CustomActions;
    import flash.display.BitmapData;
    import flash.display.DisplayObject;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.geom.Point;
    
    /**
     * ...
     * @author tibyte.kr
     */
    public class Main extends Sprite
    {
        private var form1:Form1;
        private var drawingContainer:Sprite = new Sprite();
        
        public function Main():void
        {
            if (stage)
                init();
            else
                addEventListener(Event.ADDED_TO_STAGE, init);
        }
        
        private function init(e:Event = null):void
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);
            // entry point
            stage.addEventListener(MouseEvent.RIGHT_CLICK, rightClick_h);
            form1 = new Form1();
            form1.name_input.text = "";
            form1.interfaceText.mouseEnabled = false;
            
            addChild(form1);
            addChild(drawingContainer);
            
            form1.ok_btn.addEventListener(MouseEvent.CLICK, btnClick_h);
        }
        
        private function rightClick_h(evt:MouseEvent):void
        {
            form1.title.gotoAndStop(form1.title.currentFrame % 2 + 1);
            form1.interfaceText.gotoAndStop(form1.interfaceText.currentFrame % 2 + 1);
        }
        
        private function calcData(year:intname:String):Array
        {
            var dataArray:Array = new Array(11);
            var md5:String = MD5.getMD5(name + year);
            var seed:int =parseInt("0x"+md5.slice(2, 6));
            var bmp:BitmapData = new BitmapData(220, 1);
            var luck:int;
            var offsets:Array = new Array(6);
            for (var j:int = 0; j < 6; j++)
            {
                offsets[j] = new Point(20*(new Date().getUTCFullYear()%30), 0);
            }
            
            /* 행운값 추출 */
            bmp.perlinNoise(120, 1, 6, seed,falsetrue, 7, true, offsets);
            for (var i:int = 0; i < 11; i+=1)
            {
                luck = Math.floor((Math.max(10, Math.min(80, (bmp.getPixel(i*20, 0) >> 16) / 255 * 100)) - 10) * (5 / 4));
                dataArray[i] = luck;
            }
            return dataArray.concat();
        }
        
        private function drawData(data:Array, dest:Sprite, form:Form1):void
        {
            dest.graphics.clear();
            
            /* 보조선 */
            dest.graphics.lineStyle(0.1, 0x666666);
            for (var i:int = 0; i < 11; i++)
            {
                dest.graphics.moveTo(calcX(i, form), calcY(100, form));
                dest.graphics.lineTo(calcX(i, form), calcY(0, form));
            }
            
            /* 그래프 */
            dest.graphics.lineStyle(2, 0xcc0033);
            dest.graphics.moveTo(calcX(0, form), calcY(data[0], form));
            for (var i:int = 1; i < 11; i++)
            {
                dest.graphics.lineStyle(2, 0xcc0033);
                dest.graphics.lineTo(calcX(i, form), calcY(data[i], form));
            }
        }
        
        private function calcY(value:int, form:Form1):Number
        {
            return form.point2_mc.y - (form.point2_mc.y - form.point1_mc.y) / 100 * value;
        }
        
        private function calcX(index:int, form:Form1):Number
        {
            return form.point1_mc.x + (form.point2_mc.x - form.point1_mc.x) / 10 * index;
        }
        
        private function btnClick_h(evt:MouseEvent):void
        {
            if (form1.name_input.text == "")
                return;
            var dataArray:Array = calcData(form1.age_input.value, form1.name_input.text);
            drawData(dataArray, drawingContainer, form1);
        
        }
    }
 
}














+ Recent posts