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:int, name: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,false, true, 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); } } } |