-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tzolkin.as
428 lines (357 loc) · 12 KB
/
Tzolkin.as
1
package { // /////////////////////////////////////////////////////////////////////////// // // - Tzolkin Calculator v2.3 // - 2003 - 2014 Michael Gaio (Red Spectral Serpent, kin 245) // // - Michael Gaio: www.michaelgaio.com // - Mythic Systems : www.mythicsystems.com // - Jalaka : www.jalaka.com // - Holosys : www.holosys.net // // /////////////////////////////////////////////////////////////////////////// // // - Tzolkin Calculator v2.3 by Michael Gaio is licensed under a Creative Commons Attribution 3.0 Unported License. // - Based on a work at http://www.jalaka.com/tzolkin // - http://creativecommons.org/licenses/by/3.0/ // // - Attribution is hereby given to the Mayan Tzolkin calendar system of the Mayan culture, and to the adaptations of the Mayan Tzolkin calender of the DreamSpell system of Jose Arguelles. // - Mayan Calendar : https://en.wikipedia.org/wiki/Maya_calendar // - Mayan Tzolkin: https://en.wikipedia.org/wiki/Tzolk%27in // - DreamSpell : https://en.wikipedia.org/wiki/Dreamspell // // - FREE to share, remix, modify, adapt for private or commercial use. // - Attribution is REQUIRED to be given to the Mayan Tzolkin calendar system (https://en.wikipedia.org/wiki/Tzolk%27in), and (if including any images or associated work) to the DreamSpell system of Jose Arguelles (https://en.wikipedia.org/wiki/Dreamspell), or others. // - Attribution to Michael Gaio and Mythic Systems with links to www.mythicsystems.com and www.michaelgaio.com is appreciated. // // - Bitcoin donations can be offered here: 1FT1XcTxigRFy6tF7FETr9ntvMU9Zxzk5i // // /////////////////////////////////////////////////////////////////////////// // // - Tzolkin Calculator uses MochiBot.com to track usage and distribution of the app. // - Usage and distribution for the last seven years can be viewed here: https://www.mochibot.com/my/swfdetail.html?swfid=107454b6 // - You are not required to track a distribution of the app with Mochibot, tho that will be appreciated if appropriate. // // /////////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////// import flash.events.*; import flash.display.*; import fl.controls.ComboBox; import fl.controls.Button; import flash.text.*; import fl.data.DataProvider; import fl.events.ComponentEvent; // /////////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////// public class Tzolkin extends Sprite { public var kin_title:TextField; public var day_title:TextField; // - establish variables and arrays public var tone; public var seal:String; public var sealColor; public var sealNumber; public var glyph; public var gYear; public var mYear; public var mYearTS; public var kin; public var delta; public var maxYear = 2014; public var minYear = 1850; public var dayArray = []; public var monthArray = []; public var yearArray = []; public var currentDate:Date; public var currentDay:uint; public var currentMonth:uint; public var currentYear:uint; public var toneArray = []; public var toneNameArray = []; public var sealNameArray = []; public var tzolkinArray = []; public var transYearArray = []; // UI public var button1:Button; public var comboBox1:ComboBox; public var comboBox2:ComboBox; public var comboBox3:ComboBox; public var t_about_mc:MovieClip; public var glyph_mc:MovieClip; public var kin_number:TextField; public var j_button:MovieClip; // TZOLKIN ///////////////////////////////////////////////////////////////////////////// public function Tzolkin() { //aboutWin_mc._visible = true; init(); } // INIT ///////////////////////////////////////////////////////////////////////////// public function init() { //stage.invalidate() track(); // - calculate current date currentDate = new Date(); currentDay = currentDate.getDate(); currentMonth = currentDate.getMonth(); currentYear = currentDate.getFullYear(); // - create and fill year array var y = maxYear; var j = 0; for (var i=minYear; i<=maxYear; i++) { yearArray[j] = y; y--; j++; } // fill days j = 0; for (i=1; i<=31; i++) { dayArray[j] = i; j++; } // fill months j = 0; for (i=1; i<=12; i++) { monthArray[j] = i; j++; } // - create and fill tzolkin array toneArray = ["", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13"]; toneNameArray = ["", "Magnetic", "Lunar", "Electric", "Self-Existing", "Overtone", "Rhythmic", "Resonant", "Galactic", "Solar", "Planetary", "Spectral", "Crystal", "Cosmic"]; sealNameArray = ["", "Dragon", "Wind", "Night", "Seed", "Serpent", "Worldbridger", "Hand", "Star", "Moon", "Dog", "Monkey", "Human", "Skywalker", "Wizard", "Eagle", "Warrior", "Earth", "Mirror", "Storm", "Sun"]; tzolkinArray = new Array; tzolkinArray[0] = ""; var t=1; var g=1; //trace ("/// 260 day - TZOLKIN ///"); for (var k=1; k<=260; k++) { tzolkinArray[k] = toneArray[t] + " " + sealNameArray[g]; //trace (tzolkinArray[k]); t++; g++; if (t > 13) { t = 1; } if (g > 20) { g = 1; } } // - create and fill translation year array t = 8; g = 4; y = maxYear; i = 0; while (y > 0) { transYearArray[i] = y; i++; transYearArray[i] = toneArray[t]; i++; transYearArray[i] = sealNameArray[g]; i++; t = t - 1; g = g - 5; y = y - 1; if (t < 1) { t = 13; } if (g < 4) { g = 19; } } setUI(); dateChange(); } // /////////////////////////////////////////////////////////////////////////// // - dateChange function public function dateChangeAUX(e:Event){ dateChange(); } public function dateChange(){ // - reset //aboutWin_mc._visible = false; //t_about_mc.gotoAndStop(1); // - get values var gMonth = comboBox1.selectedItem.data; var gDay = comboBox2.selectedItem.data; var gYear = comboBox3.selectedItem.data; mYear = gYear; // - fix leap year if ((gMonth == 2) && (gDay == 29)) { gDay = 28; } // - adjust year if (gMonth <= 7) { if (gDay <= 25) { mYear = gYear - 1; } else if ((gDay > 25) && (gMonth <= 6)) { mYear = gYear - 1; } } // - match to find mYearTS; var match = searchArray(transYearArray, mYear); var mYearTS = transYearArray[match+1] + " " + transYearArray[match+2]; // - find delta adjust (260-365) if (gMonth == 1) { delta = gDay + 158; } else if (gMonth == 2) { delta = gDay + 189; } else if (gMonth == 3) { delta = gDay + 217; } else if (gMonth == 4) { if (gDay < 12) { delta = gDay + 248; } else { delta = gDay - 12; } } else if (gMonth == 5) { delta = gDay + 18; } else if (gMonth == 6) { delta = gDay + 49; } else if (gMonth == 7) { if (gDay < 26) { delta = gDay + 79; } else { delta = gDay - 26; } } else if (gMonth == 8) { delta = gDay + 5; } else if (gMonth == 9) { delta = gDay + 36; } else if (gMonth == 10) { delta = gDay + 66; } else if (gMonth == 11) { delta = gDay + 97; } else if (gMonth == 12) { delta = gDay + 127; } // - match mYearTS to tzolkin match = searchArray(tzolkinArray, mYearTS); // - detrmine kin, and add delta adjust var kin = match + delta; if (kin > 260) { kin = kin - 260; } kin_title.text = "Kin: " + kin.toString(); // - tone/seal result var finalTS = tzolkinArray[kin]; //trace ("> kin: " + kin); //trace ("> finalTS: " + finalTS); // - set tone, seal, sealColor and glyph from finalTS if (finalTS.indexOf(" ") == 2) { tone = finalTS.slice(0, 2); seal = finalTS.slice(3, finalTS.length); } else { tone = finalTS.slice(0, 1); seal = finalTS.slice(2, finalTS.length); } var toneName = toneNameArray[tone]; // - set sealColor if (seal == "Dragon" || seal == "Serpent" || seal == "Moon" || seal == "Skywalker" || seal == "Earth") { sealColor = "Red"; } else if (seal == "Wind" || seal == "Worldbridger" || seal == "Dog" || seal == "Wizard" || seal == "Mirror") { sealColor = "White"; } else if (seal == "Night" || seal == "Hand" || seal == "Monkey" || seal == "Eagle" || seal == "Storm") { sealColor = "Blue"; } else { sealColor = "Yellow"; } // - set glyph var gtx = sealColor + " " + toneName + " " + seal; //trace ("gtx: " + gtx) day_title.text = gtx; // - set glyph mc glyph_mc.tone_mc.gotoAndStop(tone); sealNumber = match = searchArray(sealNameArray, seal); glyph_mc.seal_mc.gotoAndStop(sealNumber); } // /////////////////////////////////////////////////////////////////////////// // - search array function public function searchArray(array, item) { var thisArray = array; var l = thisArray.length; for (var match=0; match<l; match++) { if (thisArray[match] == item) { return match; } } } // /////////////////////////////////////////////////////////////////////////// public function setUI() { // format var tFormat:TextFormat = new TextFormat(); tFormat.font = "Trade Gothic Bold"; tFormat.color = 0x000000; tFormat.size = 25; //tFormat.align = "center"; day_title = new TextField(); day_title.defaultTextFormat = tFormat; day_title.autoSize = TextFieldAutoSize.CENTER; day_title.x = 195; day_title.y = 240; addChild(day_title); kin_title = new TextField(); kin_title.defaultTextFormat = tFormat; kin_title.autoSize = TextFieldAutoSize.CENTER; kin_title.x = 200; kin_title.y = 280; addChild(kin_title); button1 = new Button(); button1.width = 60; button1.label = "Enter"; button1.move(250, 350); //addChild(button1); //button1.addEventListener(MouseEvent.CLICK, dateChangeAUX); //button1.setStyleProperty("textColor", 0xFFFFFF); //j_button.addEventListener(MouseEvent.CLICK, openSOURCE_URL); //globalStyleFormat.applyChanges(); // - set button and combo boxes comboBox1 = new ComboBox(); comboBox2 = new ComboBox(); comboBox3 = new ComboBox(); //comboBox1.dropdownWidth = 200; comboBox1.width = 50; comboBox1.move(95, 350); //comboBox2.dropdownWidth = 200; comboBox2.width = 75; comboBox2.move(160, 350); //comboBox3.dropdownWidth = 200; comboBox3.width = 60; comboBox3.move(250, 350); addChild(comboBox1); addChild(comboBox2); addChild(comboBox3); // comboBox1.dataProvider = new DataProvider(monthArray); comboBox1.addEventListener(Event.CHANGE, comboSelect1); comboBox1.selectedIndex = currentMonth; comboBox2.dataProvider = new DataProvider(dayArray); comboBox2.addEventListener(Event.CHANGE, comboSelect2); comboBox2.selectedIndex = currentDay-1; //trace ("yearArray: " + yearArray); //trace ("> currentDay: " + (currentDay - 1).toString); //trace ("> currentMonth: " + currentMonth); //trace ("> currentYear: " + (((currentYear)-2013)-(((currentYear)-2013)*2))); comboBox3.dataProvider = new DataProvider(yearArray); comboBox3.addEventListener(Event.CHANGE, comboSelect3); comboBox3.selectedIndex = (((currentYear)-2014)-(((currentYear)-2014)*2)); } public function track() { // for Tzolkin Calc v2.3 // see shared stats here: https://www.mochibot.com/my/share_stats.html?swfid=5255d7af MochiBot.track(this, "5255d7af"); } public function comboSelect1(e:Event) { dateChange(); } public function comboSelect2(e:Event) { dateChange(); } public function comboSelect3(e:Event) { dateChange(); } public function openSOURCE_URL(e:Event) { getURL("http://www.michaelgaio.com", "_blank"); } }}